Passed
Push — html ( d230bc...4d98c2 )
by Peter
03:13
created

Mysql::toQuery()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Helper;
6
7
class Mysql
8
{
9
    public const OPTION_EMPTY       = 0;
10
    public const OPTION_PREFER_DATE = 1;
11
12
    /**
13
     * @param     $value
14
     * @param int $type
15
     * @param int $option
16
     *
17
     * @return string[]
18
     */
19
    public static function nullableParam($value, int $type = \PDO::PARAM_STR, int $option = self::OPTION_EMPTY): array
20
    {
21
        if ($value === null) {
22
            return [null, \PDO::PARAM_NULL];
23
        }
24
25
        if ($value instanceof \DateTime) {
26
            if ($option & static::OPTION_PREFER_DATE) {
27
                return [DateHelper::mysqlDate($value), $type];
28
            }
29
30
            return [DateHelper::mysqlDateTime($value), $type];
31
        }
32
33
        return [$value, $type];
34
    }
35
}
36