Test Failed
Push — develop ( eabf9f )
by Kenneth
03:54
created

MySQLLogicBindings::bBoolInt()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 1
b 0
f 0
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 or null.
13
     *
14
     * @param int|bool|null $value
15
     *
16
     * @return array
17
     * @throws InvalidArgumentException
18
     */
19
    public function bBoolNullable($value = null): array
20
    {
21
        // use NULL
22
        if ($value === null) {
23
            return [null, PDO::PARAM_NULL];
24
        }
25
26
        return $this->bBool($value);
27
    }
28
29
    /**
30
     * Bind a boolean value as bool.
31
     *
32
     * @param int|bool $value
33
     *
34
     * @return array
35
     * @throws \TypeError
36
     */
37
    public function bBool($value): array
38
    {
39
        if (!is_bool($value) && !is_int($value)) {
0 ignored issues
show
introduced by
The condition is_int($value) is always true.
Loading history...
40
            throw new \TypeError('Can not bind ' . gettype($value) . ' in boolean spot.');
41
        }
42
43
        return [(bool) $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 InvalidArgumentException
54
     */
55
    public function bBoolIntNullable($value = null): array
56
    {
57
        // use NULL
58
        if ($value === null) {
59
            return [null, PDO::PARAM_NULL];
60
        }
61
62
        return $this->bBool($value);
63
    }
64
65
    /**
66
     * Bind a boolean value as int.
67
     *
68
     * @param int|bool $value
69
     *
70
     * @return array
71
     * @throws \TypeError
72
     */
73
    public function bBoolInt($value): array
74
    {
75
        if (!is_bool($value) && !is_int($value)) {
0 ignored issues
show
introduced by
The condition is_int($value) is always true.
Loading history...
76
            throw new \TypeError('Can not bind ' . gettype($value) . ' in boolean spot.');
77
        }
78
79
        return [(int) $value, PDO::PARAM_INT];
80
    }
81
}
82