Passed
Push — master ( 2295a4...eec722 )
by Peter
10:03
created

Mysql   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A nullableParam() 0 15 4
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