Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
55.56% |
5 / 9 |
CRAP | |
88.57% |
31 / 35 |
Escaper | |
0.00% |
0 / 1 |
|
55.56% |
5 / 9 |
25.93 | |
88.57% |
31 / 35 |
quoteDateTime | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
quoteDate | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
quoteTime | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
quoteBool | |
100.00% |
1 / 1 |
5 | |
100.00% |
5 / 5 |
|||
quoteInt | |
0.00% |
0 / 1 |
4.07 | |
83.33% |
5 / 6 |
|||
quoteFloat | |
0.00% |
0 / 1 |
4.07 | |
83.33% |
5 / 6 |
|||
quoteString | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
|||
quoteObject | |
0.00% |
0 / 1 |
2.15 | |
66.67% |
2 / 3 |
|||
quoteArray | |
0.00% |
0 / 1 |
2.15 | |
66.67% |
2 / 3 |
<?php | |
declare(strict_types = 1); | |
namespace Siesta\Database; | |
use Siesta\Util\SiestaDateTime; | |
/** | |
* @author Gregor Müller | |
*/ | |
class Escaper | |
{ | |
const NULL = "NULL"; | |
/** | |
* @param SiestaDateTime|null $dateTime | |
* | |
* @return string | |
*/ | |
public static function quoteDateTime(SiestaDateTime $dateTime = null) | |
{ | |
if ($dateTime === null) { | |
return self::NULL; | |
} | |
return "'" . $dateTime->getSQLDateTime() . "'"; | |
} | |
/** | |
* @param SiestaDateTime $date | |
* | |
* @return string | |
*/ | |
public static function quoteDate(SiestaDateTime $date = null) : string | |
{ | |
if ($date === null) { | |
return self::NULL; | |
} | |
return "'" . $date->getSQLDate() . "'"; | |
} | |
/** | |
* @param SiestaDateTime $time | |
* | |
* @return string | |
*/ | |
public static function quoteTime(SiestaDateTime $time = null) : string | |
{ | |
if ($time === null) { | |
return self::NULL; | |
} | |
return "'" . $time->getSQLTime() . "'"; | |
} | |
/** | |
* @param int $value | |
* | |
* @return string | |
*/ | |
public static function quoteBool($value) : string | |
{ | |
if ($value === null) { | |
return self::NULL; | |
} | |
if ($value === "1" || $value === 1 || $value === true) { | |
return "'1'"; | |
} | |
return "'0'"; | |
} | |
/** | |
* @param int $value | |
* | |
* @return string | |
*/ | |
public static function quoteInt($value) : string | |
{ | |
if ($value === 0 || $value === false) { | |
return "'0'"; | |
} | |
if ($value === null) { | |
return self::NULL; | |
} | |
$value = (int)$value; | |
return "'" . $value . "'"; | |
} | |
/** | |
* @param float $value | |
* | |
* @return string | |
*/ | |
public static function quoteFloat($value) : string | |
{ | |
if ($value === 0 || $value === false) { | |
return "'0'"; | |
} | |
if ($value === null) { | |
return self::NULL; | |
} | |
$value = (float)$value; | |
return "'" . $value . "'"; | |
} | |
/** | |
* @param Connection $connection | |
* @param $value | |
* | |
* @return string | |
*/ | |
public static function quoteString(Connection $connection, $value) : string | |
{ | |
if ($value === null) { | |
return self::NULL; | |
} | |
return "'" . $connection->escape($value) . "'"; | |
} | |
/** | |
* @param Connection $connection | |
* @param $object | |
* | |
* @return string | |
*/ | |
public static function quoteObject(Connection $connection, $object) : string | |
{ | |
if ($object === null) { | |
return self::NULL; | |
} | |
return self::quoteString($connection, serialize($object)); | |
} | |
/** | |
* @param Connection $connection | |
* @param array|null $array | |
* | |
* @return null|string | |
*/ | |
public static function quoteArray(Connection $connection, array $array = null) | |
{ | |
if ($array === null) { | |
return self::NULL; | |
} | |
return self::quoteString($connection, json_encode($array)); | |
} | |
} |