Passed
Push — develop ( 4cf285...1f9eb4 )
by Kenneth
02:25
created

MySQLLogicBindings::bBoolNullable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace GeekLab\GLPDO2\Bindings\MySQL;
4
5
use \PDO;
6
use \TypeError;
7
use GeekLab\GLPDO2\Bindings\LogicBindingInterface;
8
9
class MySQLLogicBindings implements LogicBindingInterface
10
{
11
    /**
12
     * Bind a boolean value as bool or null.
13
     *
14
     * @param int|bool|null $value
15
     *
16
     * @return array
17
     * @throws TypeError
18
     */
19 2
    public function bBoolNullable($value = null): array
20
    {
21
        // use NULL
22 2
        if ($value === null) {
23 1
            return [null, PDO::PARAM_NULL];
24
        }
25
26 1
        return $this->bBool($value);
27
    }
28
29
    /**
30
     * Bind a boolean value as bool.
31
     *
32
     * @param int|bool|null $value
33
     *
34
     * @return array
35
     * @throws TypeError
36
     */
37 3
    public function bBool($value = null): array
38
    {
39 3
        if ($value === null) {
40 1
            throw new TypeError('Can not bind ' . gettype($value) . ':(' . $value . ') in boolean spot.');
41
        }
42
43 2
        return [$value, PDO::PARAM_BOOL];
44
    }
45
46
47
    /**
48
     * Bind a boolean value as int or null.
49
     *
50
     * @param int|bool|null $value
51
     *
52
     * @return array
53
     * @throws TypeError
54
     */
55 2
    public function bBoolIntNullable($value = null): array
56
    {
57
        // use NULL
58 2
        if ($value === null) {
59 1
            return [null, PDO::PARAM_NULL];
60
        }
61
62 1
        return $this->bBoolInt($value);
63
    }
64
65
    /**
66
     * Bind a boolean value as int.
67
     *
68
     * @param int|bool|null $value
69
     *
70
     * @return array
71
     * @throws TypeError
72
     */
73 3
    public function bBoolInt($value = null): array
74
    {
75 3
        if ($value === null) {
76 1
            throw new TypeError('Can not bind ' . gettype($value) . ':(' . $value . ') in boolean / integer spot.');
77
        }
78
79 2
        return [(int) $value, PDO::PARAM_INT];
80
    }
81
}
82