Passed
Pull Request — 2.x (#135)
by Maxim
19:55
created

WhereJsonTrait::whereJsonDoesntContainKey()   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\SQLServer\Query\Traits;
13
14
use Cycle\Database\Driver\SQLServer\Injection\CompileJson;
15
use Cycle\Database\Driver\SQLServer\Injection\CompileJsonContains;
16
use Cycle\Database\Driver\SQLServer\Injection\CompileJsonContainsKey;
17
use Cycle\Database\Driver\SQLServer\Injection\CompileJsonDoesntContain;
18
use Cycle\Database\Driver\SQLServer\Injection\CompileJsonDoesntContainKey;
19
use Cycle\Database\Driver\SQLServer\Injection\CompileJsonLength;
20
21
/**
22
 * @internal
23
 *
24
 * @psalm-internal Cycle\Database\Driver\SQLServer
25
 */
26
trait WhereJsonTrait
27
{
28
    /**
29
     * @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...
30
     */
31
    public function whereJson(string $column, mixed $value): static
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
    public function andWhereJson(string $column, mixed $value): static
47
    {
48
        return $this->whereJson($column, $value);
49
    }
50
51
    /**
52
     * @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...
53
     */
54
    public function orWhereJson(string $column, mixed $value): static
55
    {
56
        $this->registerToken(
57
            'OR',
58
            [new CompileJson($column), $value],
59
            $this->whereTokens,
60
            $this->whereWrapper()
61
        );
62
63
        return $this;
64
    }
65
66
    /**
67
     * @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...
68
     * @param bool $encode Encode the value into JSON. It is not used in this driver.
69
     * @param bool $validate Checking the value that it is valid JSON. It is not used in this driver.
70
     */
71
    public function whereJsonContains(string $column, mixed $value, bool $encode = true, bool $validate = true): static
0 ignored issues
show
Unused Code introduced by
The parameter $validate is not used and could be removed. ( Ignorable by Annotation )

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

71
    public function whereJsonContains(string $column, mixed $value, bool $encode = true, /** @scrutinizer ignore-unused */ bool $validate = true): static

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $encode is not used and could be removed. ( Ignorable by Annotation )

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

71
    public function whereJsonContains(string $column, mixed $value, /** @scrutinizer ignore-unused */ bool $encode = true, bool $validate = true): static

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
    {
73
        $this->registerToken(
74
            'AND',
75
            [new CompileJsonContains($column, $value)],
76
            $this->whereTokens,
77
            $this->whereWrapper()
78
        );
79
80
        return $this;
81
    }
82
83
    /**
84
     * @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...
85
     * @param bool $encode Encode the value into JSON. It is not used in this driver.
86
     * @param bool $validate Checking the value that it is valid JSON. It is not used in this driver.
87
     */
88
    public function andWhereJsonContains(
89
        string $column,
90
        mixed $value,
91
        bool $encode = true,
0 ignored issues
show
Unused Code introduced by
The parameter $encode is not used and could be removed. ( Ignorable by Annotation )

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

91
        /** @scrutinizer ignore-unused */ bool $encode = true,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
92
        bool $validate = true
0 ignored issues
show
Unused Code introduced by
The parameter $validate is not used and could be removed. ( Ignorable by Annotation )

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

92
        /** @scrutinizer ignore-unused */ bool $validate = true

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
    ): static {
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
     * @param bool $encode Encode the value into JSON. It is not used in this driver.
100
     * @param bool $validate Checking the value that it is valid JSON. It is not used in this driver.
101
     */
102
    public function orWhereJsonContains(
103
        string $column,
104
        mixed $value,
105
        bool $encode = true,
0 ignored issues
show
Unused Code introduced by
The parameter $encode is not used and could be removed. ( Ignorable by Annotation )

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

105
        /** @scrutinizer ignore-unused */ bool $encode = true,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
106
        bool $validate = true
0 ignored issues
show
Unused Code introduced by
The parameter $validate is not used and could be removed. ( Ignorable by Annotation )

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

106
        /** @scrutinizer ignore-unused */ bool $validate = true

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
107
    ): static {
108
        $this->registerToken(
109
            'OR',
110
            [new CompileJsonContains($column, $value)],
111
            $this->whereTokens,
112
            $this->whereWrapper()
113
        );
114
115
        return $this;
116
    }
117
118
    /**
119
     * @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...
120
     * @param bool $encode Encode the value into JSON. It is not used in this driver.
121
     * @param bool $validate Checking the value that it is valid JSON. It is not used in this driver.
122
     */
123
    public function whereJsonDoesntContain(
124
        string $column,
125
        mixed $value,
126
        bool $encode = true,
0 ignored issues
show
Unused Code introduced by
The parameter $encode is not used and could be removed. ( Ignorable by Annotation )

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

126
        /** @scrutinizer ignore-unused */ bool $encode = true,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
127
        bool $validate = true
0 ignored issues
show
Unused Code introduced by
The parameter $validate is not used and could be removed. ( Ignorable by Annotation )

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

127
        /** @scrutinizer ignore-unused */ bool $validate = true

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
128
    ): static {
129
        $this->registerToken(
130
            'AND',
131
            [new CompileJsonDoesntContain($column, $value)],
132
            $this->whereTokens,
133
            $this->whereWrapper()
134
        );
135
136
        return $this;
137
    }
138
139
    /**
140
     * @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...
141
     * @param bool $encode Encode the value into JSON. It is not used in this driver.
142
     * @param bool $validate Checking the value that it is valid JSON. It is not used in this driver.
143
     */
144
    public function andWhereJsonDoesntContain(
145
        string $column,
146
        mixed $value,
147
        bool $encode = true,
0 ignored issues
show
Unused Code introduced by
The parameter $encode is not used and could be removed. ( Ignorable by Annotation )

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

147
        /** @scrutinizer ignore-unused */ bool $encode = true,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
148
        bool $validate = true
0 ignored issues
show
Unused Code introduced by
The parameter $validate is not used and could be removed. ( Ignorable by Annotation )

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

148
        /** @scrutinizer ignore-unused */ bool $validate = true

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
149
    ): static {
150
        return $this->whereJsonDoesntContain($column, $value);
151
    }
152
153
    /**
154
     * @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...
155
     * @param bool $encode Encode the value into JSON. It is not used in this driver.
156
     * @param bool $validate Checking the value that it is valid JSON. It is not used in this driver.
157
     */
158
    public function orWhereJsonDoesntContain(
159
        string $column,
160
        mixed $value,
161
        bool $encode = true,
0 ignored issues
show
Unused Code introduced by
The parameter $encode is not used and could be removed. ( Ignorable by Annotation )

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

161
        /** @scrutinizer ignore-unused */ bool $encode = true,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
162
        bool $validate = true
0 ignored issues
show
Unused Code introduced by
The parameter $validate is not used and could be removed. ( Ignorable by Annotation )

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

162
        /** @scrutinizer ignore-unused */ bool $validate = true

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
163
    ): static {
164
        $this->registerToken(
165
            'OR',
166
            [new CompileJsonDoesntContain($column, $value)],
167
            $this->whereTokens,
168
            $this->whereWrapper()
169
        );
170
171
        return $this;
172
    }
173
174
    /**
175
     * @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...
176
     */
177
    public function whereJsonContainsKey(string $column): static
178
    {
179
        $this->registerToken(
180
            'AND',
181
            [new CompileJsonContainsKey($column)],
182
            $this->whereTokens,
183
            $this->whereWrapper()
184
        );
185
186
        return $this;
187
    }
188
189
    /**
190
     * @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...
191
     */
192
    public function andWhereJsonContainsKey(string $column): static
193
    {
194
        return $this->whereJsonContainsKey($column);
195
    }
196
197
    /**
198
     * @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...
199
     */
200
    public function orWhereJsonContainsKey(string $column): static
201
    {
202
        $this->registerToken(
203
            'OR',
204
            [new CompileJsonContainsKey($column)],
205
            $this->whereTokens,
206
            $this->whereWrapper()
207
        );
208
209
        return $this;
210
    }
211
212
    /**
213
     * @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...
214
     */
215
    public function whereJsonDoesntContainKey(string $column): static
216
    {
217
        $this->registerToken(
218
            'AND',
219
            [new CompileJsonDoesntContainKey($column)],
220
            $this->whereTokens,
221
            $this->whereWrapper()
222
        );
223
224
        return $this;
225
    }
226
227
    /**
228
     * @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...
229
     */
230
    public function andWhereJsonDoesntContainKey(string $column): static
231
    {
232
        return $this->whereJsonDoesntContainKey($column);
233
    }
234
235
    /**
236
     * @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...
237
     */
238
    public function orWhereJsonDoesntContainKey(string $column): static
239
    {
240
        $this->registerToken(
241
            'OR',
242
            [new CompileJsonDoesntContainKey($column)],
243
            $this->whereTokens,
244
            $this->whereWrapper()
245
        );
246
247
        return $this;
248
    }
249
250
    /**
251
     * @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...
252
     * @param int<0, max> $length
253
     * @param non-empty-string $operator
254
     */
255
    public function whereJsonLength(string $column, int $length, string $operator = '='): static
256
    {
257
        $this->registerToken(
258
            'AND',
259
            [new CompileJsonLength($column, $length, $operator)],
260
            $this->whereTokens,
261
            $this->whereWrapper()
262
        );
263
264
        return $this;
265
    }
266
267
    /**
268
     * @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...
269
     * @param int<0, max> $length
270
     * @param non-empty-string $operator
271
     */
272
    public function andWhereJsonLength(string $column, int $length, string $operator = '='): static
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
    public function orWhereJsonLength(string $column, int $length, string $operator = '='): static
283
    {
284
        $this->registerToken(
285
            'OR',
286
            [new CompileJsonLength($column, $length, $operator)],
287
            $this->whereTokens,
288
            $this->whereWrapper()
289
        );
290
291
        return $this;
292
    }
293
}
294