MySQLLogicBindings   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 46
ccs 12
cts 12
cp 1
rs 10
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A bBool() 0 12 5
A bBoolInt() 0 12 5
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