MySQLLogicBindings::bBool()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 5
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 12
ccs 6
cts 6
cp 1
crap 5
rs 9.6111
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
The doc comment array{?bool, int} at position 2 could not be parsed: Expected ':' at position 2, but found '?bool'.
Loading history...
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
Documentation Bug introduced by
The doc comment array{?int, int} at position 2 could not be parsed: Expected ':' at position 2, but found '?int'.
Loading history...
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