Passed
Pull Request — 2.x (#135)
by
unknown
20:30
created

WhereJsonTrait::orWhereJsonContainsKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 10
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
 * @psalm-internal Cycle\Database\Driver\Postgres
26
 */
27
trait WhereJsonTrait
28
{
29
    /**
30
     * @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...
31
     */
32
    public function whereJson(string $column, mixed $value): static
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
    public function andWhereJson(string $column, mixed $value): static
48
    {
49
        return $this->whereJson($column, $value);
50
    }
51
52
    /**
53
     * @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...
54
     */
55
    public function orWhereJson(string $column, mixed $value): static
56
    {
57
        $this->registerToken(
58
            'OR',
59
            [new CompileJson($column), $value],
60
            $this->whereTokens,
61
            $this->whereWrapper()
62
        );
63
64
        return $this;
65
    }
66
67
    /**
68
     * @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...
69
     * @param bool $encode Encode the value into JSON.
70
     * @param bool $validate Checking the value that it is valid JSON.
71
     */
72
    public function whereJsonContains(string $column, mixed $value, bool $encode = true, bool $validate = true): static
73
    {
74
        $this->registerToken(
75
            'AND',
76
            [new CompileJsonContains($column, Jsoner::toJson($value, $encode, $validate))],
77
            $this->whereTokens,
78
            $this->whereWrapper()
79
        );
80
81
        return $this;
82
    }
83
84
    /**
85
     * @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...
86
     * @param bool $encode Encode the value into JSON.
87
     * @param bool $validate Checking the value that it is valid JSON.
88
     */
89
    public function andWhereJsonContains(
90
        string $column,
91
        mixed $value,
92
        bool $encode = true,
93
        bool $validate = true
94
    ): static {
95
        return $this->whereJsonContains($column, $value, $encode, $validate);
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
     * @param bool $encode Encode the value into JSON.
101
     * @param bool $validate Checking the value that it is valid JSON.
102
     */
103
    public function orWhereJsonContains(
104
        string $column,
105
        mixed $value,
106
        bool $encode = true,
107
        bool $validate = true
108
    ): static {
109
        $this->registerToken(
110
            'OR',
111
            [new CompileJsonContains($column, Jsoner::toJson($value, $encode, $validate))],
112
            $this->whereTokens,
113
            $this->whereWrapper()
114
        );
115
116
        return $this;
117
    }
118
119
    /**
120
     * @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...
121
     * @param bool $encode Encode the value into JSON.
122
     * @param bool $validate Checking the value that it is valid JSON.
123
     */
124
    public function whereJsonDoesntContain(
125
        string $column,
126
        mixed $value,
127
        bool $encode = true,
128
        bool $validate = true
129
    ): static {
130
        $this->registerToken(
131
            'AND',
132
            [new CompileJsonDoesntContain($column, Jsoner::toJson($value, $encode, $validate))],
133
            $this->whereTokens,
134
            $this->whereWrapper()
135
        );
136
137
        return $this;
138
    }
139
140
    /**
141
     * @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...
142
     * @param bool $encode Encode the value into JSON.
143
     * @param bool $validate Checking the value that it is valid JSON.
144
     */
145
    public function andWhereJsonDoesntContain(
146
        string $column,
147
        mixed $value,
148
        bool $encode = true,
149
        bool $validate = true
150
    ): static {
151
        return $this->whereJsonDoesntContain($column, $value, $encode, $validate);
152
    }
153
154
    /**
155
     * @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...
156
     * @param bool $encode Encode the value into JSON.
157
     * @param bool $validate Checking the value that it is valid JSON.
158
     */
159
    public function orWhereJsonDoesntContain(
160
        string $column,
161
        mixed $value,
162
        bool $encode = true,
163
        bool $validate = true
164
    ): static {
165
        $this->registerToken(
166
            'OR',
167
            [new CompileJsonDoesntContain($column, Jsoner::toJson($value, $encode, $validate))],
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
    public function whereJsonContainsKey(string $column): static
179
    {
180
        $this->registerToken(
181
            'AND',
182
            [new CompileJsonContainsKey($column)],
183
            $this->whereTokens,
184
            $this->whereWrapper()
185
        );
186
187
        return $this;
188
    }
189
190
    /**
191
     * @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...
192
     */
193
    public function andWhereJsonContainsKey(string $column): static
194
    {
195
        return $this->whereJsonContainsKey($column);
196
    }
197
198
    /**
199
     * @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...
200
     */
201
    public function orWhereJsonContainsKey(string $column): static
202
    {
203
        $this->registerToken(
204
            'OR',
205
            [new CompileJsonContainsKey($column)],
206
            $this->whereTokens,
207
            $this->whereWrapper()
208
        );
209
210
        return $this;
211
    }
212
213
    /**
214
     * @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...
215
     */
216
    public function whereJsonDoesntContainKey(string $column): static
217
    {
218
        $this->registerToken(
219
            'AND',
220
            [new CompileJsonDoesntContainKey($column)],
221
            $this->whereTokens,
222
            $this->whereWrapper()
223
        );
224
225
        return $this;
226
    }
227
228
    /**
229
     * @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...
230
     */
231
    public function andWhereJsonDoesntContainKey(string $column): static
232
    {
233
        return $this->whereJsonDoesntContainKey($column);
234
    }
235
236
    /**
237
     * @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...
238
     */
239
    public function orWhereJsonDoesntContainKey(string $column): static
240
    {
241
        $this->registerToken(
242
            'OR',
243
            [new CompileJsonDoesntContainKey($column)],
244
            $this->whereTokens,
245
            $this->whereWrapper()
246
        );
247
248
        return $this;
249
    }
250
251
    /**
252
     * @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...
253
     * @param int<0, max> $length
254
     * @param non-empty-string $operator
255
     */
256
    public function whereJsonLength(string $column, int $length, string $operator = '='): static
257
    {
258
        $this->registerToken(
259
            'AND',
260
            [new CompileJsonLength($column, $length, $operator)],
261
            $this->whereTokens,
262
            $this->whereWrapper()
263
        );
264
265
        return $this;
266
    }
267
268
    /**
269
     * @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...
270
     * @param int<0, max> $length
271
     * @param non-empty-string $operator
272
     */
273
    public function andWhereJsonLength(string $column, int $length, string $operator = '='): static
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
    public function orWhereJsonLength(string $column, int $length, string $operator = '='): static
284
    {
285
        $this->registerToken(
286
            'OR',
287
            [new CompileJsonLength($column, $length, $operator)],
288
            $this->whereTokens,
289
            $this->whereWrapper()
290
        );
291
292
        return $this;
293
    }
294
}
295