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\Postgres\Query\Traits;
13
14
use Cycle\Database\Driver\Jsoner;
15
use Cycle\Database\Driver\Postgres\Injection\CompileJson;
16
use Cycle\Database\Driver\Postgres\Injection\CompileJsonContains;
17
use Cycle\Database\Driver\Postgres\Injection\CompileJsonContainsKey;
18
use Cycle\Database\Driver\Postgres\Injection\CompileJsonDoesntContain;
19
use Cycle\Database\Driver\Postgres\Injection\CompileJsonDoesntContainKey;
20
use Cycle\Database\Driver\Postgres\Injection\CompileJsonLength;
21
22
/**
23
 * @internal
24
 */
25
trait WhereJsonTrait
26
{
27
    /**
28
     * @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...
29
     *
30
     * @return $this|self
31
     */
32
    public function whereJson(string $column, mixed $value): self
33
    {
34
        $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

34
        $this->/** @scrutinizer ignore-call */ 
35
               registerToken(
Loading history...
35
            'AND',
36
            [new CompileJson($column), $value],
37
            $this->whereTokens,
38
            $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

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