Passed
Push — master ( bd6e6f...61c111 )
by Kenneth
01:39
created

Bindings::bIntArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace GeekLab\GLPDO2\Bindings;
4
5
use \PDO;
6
use \Exception;
7
use \DomainException;
8
use \JsonException;
9
10
class Bindings
11
{
12
    /** @var DateTimeBindingInterface $dateTime */
13
    protected $dateTime;
14
15
    /** @var LogicBindingInterface $logic */
16
    protected $logic;
17
18
    /** @var NumericBindingInterface $numeric */
19
    protected $numeric;
20
21
    /** @var RawBindingInterface $raw */
22
    protected $raw;
23
24
    /** @var StringBindingInterface $string */
25
    protected $string;
26
27
    public function __construct(
28
        DateTimeBindingInterface $dateTime,
29
        LogicBindingInterface $logic,
30
        NumericBindingInterface $numeric,
31
        RawBindingInterface $raw,
32
        StringBindingInterface $string
33
    ) {
34
        $this->dateTime = $dateTime;
35
        $this->logic = $logic;
36
        $this->numeric = $numeric;
37
        $this->raw = $raw;
38
        $this->string = $string;
39
    }
40
41
    /**
42
     * Bind a boolean value as bool, with NULL option.
43
     *
44
     * @param int|bool|null $value
45
     * @param bool $null
46
     *
47
     * @return array
48
     * @throws Exception
49
     */
50
    public function bBool($value = null, bool $null = false): array
51
    {
52
        return $this->logic->bBool($value, $null);
53
    }
54
55
    /**
56
     * Bind a boolean value as int, with NULL option.
57
     *
58
     * @param int|bool|null $value
59
     * @param bool $null
60
     *
61
     * @return array
62
     * @throws Exception
63
     */
64
    public function bBoolInt($value = null, bool $null = false): array
65
    {
66
        return $this->logic->bBoolInt($value, $null);
67
    }
68
69
    /**
70
     * Bind a date value as date or optional NULL.
71
     * YYYY-MM-DD is the proper date format.
72
     *
73
     * @param string|null $value
74
     * @param bool $null
75
     *
76
     * @return array
77
     * @throws Exception
78
     */
79
    public function bDate(?string $value, bool $null = false): array
80
    {
81
        return $this->dateTime->bDate($value, $null);
82
    }
83
84
    /**
85
     * Bind a date value as date time or optional NULL.
86
     * YYYY-MM-DD HH:MM:SS is the proper date format.
87
     *
88
     * @param string|null $value
89
     * @param bool $null
90
     *
91
     * @return array
92
     * @throws Exception
93
     */
94
    public function bDateTime($value = null, bool $null = false): array
95
    {
96
        return $this->dateTime->bDateTime($value, $null);
97
    }
98
99
    /**
100
     * Bind a float.
101
     *
102
     * @param string|int|float|null $value
103
     * @param int $decimals
104
     * @param bool $null
105
     *
106
     * @return array
107
     * @throws Exception
108
     */
109
    public function bFloat($value = null, $decimals = 3, $null = false): array
110
    {
111
        return $this->numeric->bFloat($value, $decimals, $null);
112
    }
113
114
    /**
115
     * Bind an integer with optional NULL.
116
     *
117
     * @param string|int|float|bool|null $value
118
     * @param bool $null
119
     *
120
     * @return array
121
     * @throws Exception
122
     */
123
    public function bInt($value = null, bool $null = false): array
124
    {
125
        return $this->numeric->bInt($value, $null);
126
    }
127
128
    /**
129
     * Convert array of integers to comma separated values. Uses %%
130
     * Great for IN() statements.
131
     *
132
     * @param array $data
133
     * @param int $default
134
     *
135
     * @return array
136
     * @throws Exception
137
     */
138
    public function bIntArray(array $data, int $default = 0): array
139
    {
140
        return $this->numeric->bIntArray($data, $default);
141
    }
142
143
    /**
144
     * Bind a object or JSON string to a string
145
     *
146
     * @param string|object|null $value
147
     * @param bool $null
148
     *
149
     * @return array
150
     * @throws JsonException
151
     */
152
    public function bJSON($value, bool $null = false): array
153
    {
154
        return $this->string->bJSON($value, $null);
155
    }
156
157
    /**
158
     * Create and bind string for LIKE() statements.
159
     *
160
     * @param string $value
161
     * @param bool $ends Ends with?
162
     * @param bool $starts Starts with?
163
     *
164
     * @return array
165
     */
166
    public function bLike(string $value, bool $ends = false, bool $starts = false): array
167
    {
168
        return $this->string->bLike($value, $ends, $starts);
169
    }
170
171
    /**
172
     * !!!DANGER!!!
173
     * Bind a raw value.
174
     *
175
     * @param string|int|float|bool $value
176
     *
177
     * @return array
178
     */
179
    public function bRaw($value): array
180
    {
181
        return $this->raw->bRaw($value);
182
    }
183
184
    /**
185
     * Bind a string value.
186
     *
187
     * @param string|int|float|bool|null $value
188
     * @param bool $null
189
     * @param int $type
190
     *
191
     * @return array
192
     * @throws Exception
193
     */
194
    public function bStr($value, bool $null = false, int $type = PDO::PARAM_STR): array
195
    {
196
        return $this->string->bStr($value, $null, $type);
197
    }
198
199
    /**
200
     * Convert an array into a string and bind it.
201
     * Great for IN() statements.
202
     *
203
     * @param array $values
204
     * @param string|int|float|bool $default
205
     *
206
     * @return array
207
     */
208
    public function bStrArr(array $values, $default = ''): array
209
    {
210
        return $this->string->bStrArr($values, $default);
211
    }
212
}
213