1 | <?php |
||
2 | |||
3 | namespace GeekLab\GLPDO2\Bindings\MySQL; |
||
4 | |||
5 | use PDO; |
||
6 | use InvalidArgumentException; |
||
7 | use GeekLab\GLPDO2\Bindings\LogicBindingInterface; |
||
8 | |||
9 | class MySQLLogicBindings implements LogicBindingInterface |
||
10 | { |
||
11 | /** |
||
12 | * Bind a boolean value as bool, with NULL option. |
||
13 | * |
||
14 | * @param bool | int | null $value |
||
15 | * @param bool $null |
||
16 | * |
||
17 | * @return array{?bool, int} |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
18 | * @throws InvalidArgumentException |
||
19 | */ |
||
20 | 4 | public function bBool(bool | int | null $value = null, bool $null = false): array |
|
21 | { |
||
22 | // use NULL |
||
23 | 4 | if ($value === null && $null) { |
|
24 | 1 | return [null, PDO::PARAM_NULL]; |
|
25 | } |
||
26 | |||
27 | 3 | if ($value === null && $null === false) { |
|
28 | 1 | throw new InvalidArgumentException('Can not bind NULL in boolean spot.'); |
|
29 | } |
||
30 | |||
31 | 2 | return [(bool)$value, PDO::PARAM_BOOL]; |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * Bind a boolean value as int, with NULL option. |
||
36 | * |
||
37 | * @param bool | int | null $value |
||
38 | * @param bool $null |
||
39 | * |
||
40 | * @return array{?int, int} |
||
0 ignored issues
–
show
|
|||
41 | * @throws InvalidArgumentException |
||
42 | */ |
||
43 | 4 | public function bBoolInt(bool | int | null $value = null, bool $null = false): array |
|
44 | { |
||
45 | // use NULL |
||
46 | 4 | if ($value === null && $null) { |
|
47 | 1 | return [null, PDO::PARAM_NULL]; |
|
48 | } |
||
49 | |||
50 | 3 | if ($value === null && $null === false) { |
|
51 | 1 | throw new InvalidArgumentException('Can not bind NULL in boolean spot.'); |
|
52 | } |
||
53 | |||
54 | 2 | return [(int)$value, PDO::PARAM_INT]; |
|
55 | } |
||
56 | } |
||
57 |