Passed
Pull Request — 2.x (#135)
by Aleksei
18:00
created

WhereJsonTrait::andWhereJsonDoesntContain()   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
/**
4
 * This file is part of Cycle ORM package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Cycle\Database\Driver\MySQL\Query\Traits;
13
14
use Cycle\Database\Driver\MySQL\Injection\CompileJson;
15
use Cycle\Database\Driver\MySQL\Injection\CompileJsonContains;
16
use Cycle\Database\Driver\MySQL\Injection\CompileJsonContainsKey;
17
use Cycle\Database\Driver\MySQL\Injection\CompileJsonDoesntContain;
18
use Cycle\Database\Driver\MySQL\Injection\CompileJsonDoesntContainKey;
19
use Cycle\Database\Driver\MySQL\Injection\CompileJsonLength;
20
21
/**
22
 * @internal
23
 */
24
trait WhereJsonTrait
25
{
26
    /**
27
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
28
     *
29
     * @return $this|self
30
     */
31
    public function whereJson(string $column, mixed $value): self
32
    {
33
        $this->registerToken(
0 ignored issues
show
Bug introduced by
It seems like registerToken() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $this->/** @scrutinizer ignore-call */ 
34
               registerToken(
Loading history...
34
            'AND',
35
            [new CompileJson($column), $value],
36
            $this->whereTokens,
37
            $this->whereWrapper()
0 ignored issues
show
Bug introduced by
It seems like whereWrapper() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
            $this->/** @scrutinizer ignore-call */ 
38
                   whereWrapper()
Loading history...
38
        );
39
40
        return $this;
41
    }
42
43
    /**
44
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
45
     *
46
     * @return $this|self
47
     */
48
    public function andWhereJson(string $column, mixed $value): self
49
    {
50
        return $this->whereJson($column, $value);
51
    }
52
53
    /**
54
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
55
     *
56
     * @return $this|self
57
     */
58
    public function orWhereJson(string $column, mixed $value): self
59
    {
60
        $this->registerToken(
61
            'OR',
62
            [new CompileJson($column), $value],
63
            $this->whereTokens,
64
            $this->whereWrapper()
65
        );
66
67
        return $this;
68
    }
69
70
    /**
71
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
72
     *
73
     * @return $this|self
74
     */
75
    public function whereJsonContains(string $column, mixed $value): self
76
    {
77
        $this->registerToken(
78
            'AND',
79
            [new CompileJsonContains($column, json_validate($value) ? $value : \json_encode($value))],
80
            $this->whereTokens,
81
            $this->whereWrapper()
82
        );
83
84
        return $this;
85
    }
86
87
    /**
88
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
89
     *
90
     * @return $this|self
91
     */
92
    public function andWhereJsonContains(string $column, mixed $value): self
93
    {
94
        return $this->whereJsonContains($column, $value);
95
    }
96
97
    /**
98
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
99
     *
100
     * @return $this|self
101
     */
102
    public function orWhereJsonContains(string $column, mixed $value): self
103
    {
104
        $this->registerToken(
105
            'OR',
106
            [new CompileJsonContains($column, json_validate($value) ? $value : \json_encode($value))],
107
            $this->whereTokens,
108
            $this->whereWrapper()
109
        );
110
111
        return $this;
112
    }
113
114
    /**
115
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
116
     *
117
     * @return $this|self
118
     */
119
    public function whereJsonDoesntContain(string $column, mixed $value): self
120
    {
121
        $this->registerToken(
122
            'AND',
123
            [new CompileJsonDoesntContain($column, json_validate($value) ? $value : \json_encode($value))],
124
            $this->whereTokens,
125
            $this->whereWrapper()
126
        );
127
128
        return $this;
129
    }
130
131
    /**
132
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
133
     *
134
     * @return $this|self
135
     */
136
    public function andWhereJsonDoesntContain(string $column, mixed $value): self
137
    {
138
        return $this->whereJsonDoesntContain($column, $value);
139
    }
140
141
    /**
142
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
143
     *
144
     * @return $this|self
145
     */
146
    public function orWhereJsonDoesntContain(string $column, mixed $value): self
147
    {
148
        $this->registerToken(
149
            'OR',
150
            [new CompileJsonDoesntContain($column, json_validate($value) ? $value : \json_encode($value))],
151
            $this->whereTokens,
152
            $this->whereWrapper()
153
        );
154
155
        return $this;
156
    }
157
158
    /**
159
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
160
     *
161
     * @return $this|self
162
     */
163
    public function whereJsonContainsKey(string $column): self
164
    {
165
        $this->registerToken(
166
            'AND',
167
            [new CompileJsonContainsKey($column)],
168
            $this->whereTokens,
169
            $this->whereWrapper()
170
        );
171
172
        return $this;
173
    }
174
175
    /**
176
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
177
     *
178
     * @return $this|self
179
     */
180
    public function andWhereJsonContainsKey(string $column): self
181
    {
182
        return $this->whereJsonContainsKey($column);
183
    }
184
185
    /**
186
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
187
     *
188
     * @return $this|self
189
     */
190
    public function orWhereJsonContainsKey(string $column): self
191
    {
192
        $this->registerToken(
193
            'OR',
194
            [new CompileJsonContainsKey($column)],
195
            $this->whereTokens,
196
            $this->whereWrapper()
197
        );
198
199
        return $this;
200
    }
201
202
    /**
203
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
204
     *
205
     * @return $this|self
206
     */
207
    public function whereJsonDoesntContainKey(string $column): self
208
    {
209
        $this->registerToken(
210
            'AND',
211
            [new CompileJsonDoesntContainKey($column)],
212
            $this->whereTokens,
213
            $this->whereWrapper()
214
        );
215
216
        return $this;
217
    }
218
219
    /**
220
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
221
     *
222
     * @return $this|self
223
     */
224
    public function andWhereJsonDoesntContainKey(string $column): self
225
    {
226
        return $this->whereJsonDoesntContainKey($column);
227
    }
228
229
    /**
230
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
231
     *
232
     * @return $this|self
233
     */
234
    public function orWhereJsonDoesntContainKey(string $column): self
235
    {
236
        $this->registerToken(
237
            'OR',
238
            [new CompileJsonDoesntContainKey($column)],
239
            $this->whereTokens,
240
            $this->whereWrapper()
241
        );
242
243
        return $this;
244
    }
245
246
    /**
247
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
248
     * @param int<0, max> $length
249
     * @param non-empty-string $operator
250
     *
251
     * @return $this|self
252
     */
253
    public function whereJsonLength(string $column, int $length, string $operator = '='): self
254
    {
255
        $this->registerToken(
256
            'AND',
257
            [new CompileJsonLength($column, $length, $operator)],
258
            $this->whereTokens,
259
            $this->whereWrapper()
260
        );
261
262
        return $this;
263
    }
264
265
    /**
266
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
267
     * @param int<0, max> $length
268
     * @param non-empty-string $operator
269
     *
270
     * @return $this|self
271
     */
272
    public function andWhereJsonLength(string $column, int $length, string $operator = '='): self
273
    {
274
        return $this->whereJsonLength($column, $length, $operator);
275
    }
276
277
    /**
278
     * @param non-empty-string $column
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
279
     * @param int<0, max> $length
280
     * @param non-empty-string $operator
281
     *
282
     * @return $this|self
283
     */
284
    public function orWhereJsonLength(string $column, int $length, string $operator = '='): self
285
    {
286
        $this->registerToken(
287
            'OR',
288
            [new CompileJsonLength($column, $length, $operator)],
289
            $this->whereTokens,
290
            $this->whereWrapper()
291
        );
292
293
        return $this;
294
    }
295
}
296