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

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

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

36
            $this->/** @scrutinizer ignore-call */ 
37
                   whereWrapper()
Loading history...
37
        );
38
39
        return $this;
40
    }
41
42
    /**
43
     * @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...
44
     *
45
     * @return $this|self
46
     */
47
    public function andWhereJson(string $column, mixed $value): self
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
     * @return $this|self
56
     */
57
    public function orWhereJson(string $column, mixed $value): self
58
    {
59
        $this->registerToken(
60
            'OR',
61
            [new CompileJson($column), $value],
62
            $this->whereTokens,
63
            $this->whereWrapper()
64
        );
65
66
        return $this;
67
    }
68
69
    /**
70
     * @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...
71
     *
72
     * @return $this|self
73
     */
74
    public function whereJsonContains(string $column, mixed $value): self
0 ignored issues
show
Unused Code introduced by
The parameter $column 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

74
    public function whereJsonContains(/** @scrutinizer ignore-unused */ string $column, mixed $value): self

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 $value 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

74
    public function whereJsonContains(string $column, /** @scrutinizer ignore-unused */ mixed $value): self

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...
75
    {
76
        throw new DriverException('This database engine does not support JSON contains operations.');
77
    }
78
79
    /**
80
     * @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...
81
     *
82
     * @return $this|self
83
     */
84
    public function andWhereJsonContains(string $column, mixed $value): self
0 ignored issues
show
Unused Code introduced by
The parameter $column 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

84
    public function andWhereJsonContains(/** @scrutinizer ignore-unused */ string $column, mixed $value): self

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 $value 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

84
    public function andWhereJsonContains(string $column, /** @scrutinizer ignore-unused */ mixed $value): self

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...
85
    {
86
        throw new DriverException('This database engine does not support JSON contains operations.');
87
    }
88
89
    /**
90
     * @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...
91
     *
92
     * @return $this|self
93
     */
94
    public function orWhereJsonContains(string $column, mixed $value): self
0 ignored issues
show
Unused Code introduced by
The parameter $value 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

94
    public function orWhereJsonContains(string $column, /** @scrutinizer ignore-unused */ mixed $value): self

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 $column 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

94
    public function orWhereJsonContains(/** @scrutinizer ignore-unused */ string $column, mixed $value): self

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...
95
    {
96
        throw new DriverException('This database engine does not support JSON contains operations.');
97
    }
98
99
    /**
100
     * @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...
101
     *
102
     * @return $this|self
103
     */
104
    public function whereJsonDoesntContain(string $column, mixed $value): self
0 ignored issues
show
Unused Code introduced by
The parameter $value 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

104
    public function whereJsonDoesntContain(string $column, /** @scrutinizer ignore-unused */ mixed $value): self

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 $column 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

104
    public function whereJsonDoesntContain(/** @scrutinizer ignore-unused */ string $column, mixed $value): self

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...
105
    {
106
        throw new DriverException('This database engine does not support JSON contains operations.');
107
    }
108
109
    /**
110
     * @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...
111
     *
112
     * @return $this|self
113
     */
114
    public function andWhereJsonDoesntContain(string $column, mixed $value): self
0 ignored issues
show
Unused Code introduced by
The parameter $value 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

114
    public function andWhereJsonDoesntContain(string $column, /** @scrutinizer ignore-unused */ mixed $value): self

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 $column 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

114
    public function andWhereJsonDoesntContain(/** @scrutinizer ignore-unused */ string $column, mixed $value): self

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...
115
    {
116
        throw new DriverException('This database engine does not support JSON contains operations.');
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
     *
122
     * @return $this|self
123
     */
124
    public function orWhereJsonDoesntContain(string $column, mixed $value): self
0 ignored issues
show
Unused Code introduced by
The parameter $column 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

124
    public function orWhereJsonDoesntContain(/** @scrutinizer ignore-unused */ string $column, mixed $value): self

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 $value 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

124
    public function orWhereJsonDoesntContain(string $column, /** @scrutinizer ignore-unused */ mixed $value): self

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...
125
    {
126
        throw new DriverException('This database engine does not support JSON contains operations.');
127
    }
128
129
    /**
130
     * @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...
131
     *
132
     * @return $this|self
133
     */
134
    public function whereJsonContainsKey(string $column): self
135
    {
136
        $this->registerToken(
137
            'AND',
138
            [new CompileJsonContainsKey($column)],
139
            $this->whereTokens,
140
            $this->whereWrapper()
141
        );
142
143
        return $this;
144
    }
145
146
    /**
147
     * @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...
148
     *
149
     * @return $this|self
150
     */
151
    public function andWhereJsonContainsKey(string $column): self
152
    {
153
        return $this->whereJsonContainsKey($column);
154
    }
155
156
    /**
157
     * @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...
158
     *
159
     * @return $this|self
160
     */
161
    public function orWhereJsonContainsKey(string $column): self
162
    {
163
        $this->registerToken(
164
            'OR',
165
            [new CompileJsonContainsKey($column)],
166
            $this->whereTokens,
167
            $this->whereWrapper()
168
        );
169
170
        return $this;
171
    }
172
173
    /**
174
     * @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...
175
     *
176
     * @return $this|self
177
     */
178
    public function whereJsonDoesntContainKey(string $column): self
179
    {
180
        $this->registerToken(
181
            'AND',
182
            [new CompileJsonDoesntContainKey($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
     * @return $this|self
194
     */
195
    public function andWhereJsonDoesntContainKey(string $column): self
196
    {
197
        return $this->whereJsonDoesntContainKey($column);
198
    }
199
200
    /**
201
     * @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...
202
     *
203
     * @return $this|self
204
     */
205
    public function orWhereJsonDoesntContainKey(string $column): self
206
    {
207
        $this->registerToken(
208
            'OR',
209
            [new CompileJsonDoesntContainKey($column)],
210
            $this->whereTokens,
211
            $this->whereWrapper()
212
        );
213
214
        return $this;
215
    }
216
217
    /**
218
     * @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...
219
     * @param int<0, max> $length
220
     * @param non-empty-string $operator
221
     *
222
     * @return $this|self
223
     */
224
    public function whereJsonLength(string $column, int $length, string $operator = '='): self
225
    {
226
        $this->registerToken(
227
            'AND',
228
            [new CompileJsonLength($column, $length, $operator)],
229
            $this->whereTokens,
230
            $this->whereWrapper()
231
        );
232
233
        return $this;
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
     * @param int<0, max> $length
239
     * @param non-empty-string $operator
240
     *
241
     * @return $this|self
242
     */
243
    public function andWhereJsonLength(string $column, int $length, string $operator = '='): self
244
    {
245
        return $this->whereJsonLength($column, $length, $operator);
246
    }
247
248
    /**
249
     * @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...
250
     * @param int<0, max> $length
251
     * @param non-empty-string $operator
252
     *
253
     * @return $this|self
254
     */
255
    public function orWhereJsonLength(string $column, int $length, string $operator = '='): self
256
    {
257
        $this->registerToken(
258
            'OR',
259
            [new CompileJsonLength($column, $length, $operator)],
260
            $this->whereTokens,
261
            $this->whereWrapper()
262
        );
263
264
        return $this;
265
    }
266
}
267