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

WhereJsonTrait::orWhereJsonDoesntContainKey()   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\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
 * @psalm-internal Cycle\Database\Driver\SQLite
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
    public function whereJson(string $column, mixed $value): static
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
    public function andWhereJson(string $column, mixed $value): static
46
    {
47
        return $this->whereJson($column, $value);
48
    }
49
50
    /**
51
     * @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...
52
     */
53
    public function orWhereJson(string $column, mixed $value): static
54
    {
55
        $this->registerToken(
56
            'OR',
57
            [new CompileJson($column), $value],
58
            $this->whereTokens,
59
            $this->whereWrapper()
60
        );
61
62
        return $this;
63
    }
64
65
    /**
66
     * @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...
67
     * @param bool $encode Encode the value into JSON.
68
     * @param bool $validate Checking the value that it is valid JSON.
69
     */
70
    public function whereJsonContains(string $column, mixed $value, bool $encode = true, bool $validate = true): static
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

70
    public function whereJsonContains(string $column, /** @scrutinizer ignore-unused */ mixed $value, 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...
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

70
    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

70
    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...
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

70
    public function whereJsonContains(/** @scrutinizer ignore-unused */ string $column, mixed $value, 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...
71
    {
72
        throw new DriverException('This database engine does not support JSON contains operations.');
73
    }
74
75
    /**
76
     * @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...
77
     * @param bool $encode Encode the value into JSON.
78
     * @param bool $validate Checking the value that it is valid JSON.
79
     */
80
    public function andWhereJsonContains(
81
        string $column,
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

81
        /** @scrutinizer ignore-unused */ string $column,

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...
82
        mixed $value,
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

82
        /** @scrutinizer ignore-unused */ mixed $value,

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...
83
        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

83
        /** @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...
84
        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

84
        /** @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...
85
    ): static {
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
     * @param bool $encode Encode the value into JSON.
92
     * @param bool $validate Checking the value that it is valid JSON.
93
     */
94
    public function orWhereJsonContains(
95
        string $column,
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

95
        /** @scrutinizer ignore-unused */ string $column,

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...
96
        mixed $value,
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

96
        /** @scrutinizer ignore-unused */ mixed $value,

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...
97
        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

97
        /** @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...
98
        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

98
        /** @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...
99
    ): static {
100
        throw new DriverException('This database engine does not support JSON contains operations.');
101
    }
102
103
    /**
104
     * @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...
105
     * @param bool $encode Encode the value into JSON.
106
     * @param bool $validate Checking the value that it is valid JSON.
107
     */
108
    public function whereJsonDoesntContain(
109
        string $column,
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

109
        /** @scrutinizer ignore-unused */ string $column,

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...
110
        mixed $value,
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

110
        /** @scrutinizer ignore-unused */ mixed $value,

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...
111
        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

111
        /** @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...
112
        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

112
        /** @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...
113
    ): static {
114
        throw new DriverException('This database engine does not support JSON contains operations.');
115
    }
116
117
    /**
118
     * @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...
119
     * @param bool $encode Encode the value into JSON.
120
     * @param bool $validate Checking the value that it is valid JSON.
121
     */
122
    public function andWhereJsonDoesntContain(
123
        string $column,
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

123
        /** @scrutinizer ignore-unused */ string $column,

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...
124
        mixed $value,
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

124
        /** @scrutinizer ignore-unused */ mixed $value,

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

125
        /** @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...
126
        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

126
        /** @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...
127
    ): static {
128
        throw new DriverException('This database engine does not support JSON contains operations.');
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
     * @param bool $encode Encode the value into JSON.
134
     * @param bool $validate Checking the value that it is valid JSON.
135
     */
136
    public function orWhereJsonDoesntContain(
137
        string $column,
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

137
        /** @scrutinizer ignore-unused */ string $column,

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...
138
        mixed $value,
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

138
        /** @scrutinizer ignore-unused */ mixed $value,

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...
139
        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

139
        /** @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...
140
        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

140
        /** @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...
141
    ): static {
142
        throw new DriverException('This database engine does not support JSON contains operations.');
143
    }
144
145
    /**
146
     * @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...
147
     */
148
    public function whereJsonContainsKey(string $column): static
149
    {
150
        $this->registerToken(
151
            'AND',
152
            [new CompileJsonContainsKey($column)],
153
            $this->whereTokens,
154
            $this->whereWrapper()
155
        );
156
157
        return $this;
158
    }
159
160
    /**
161
     * @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...
162
     */
163
    public function andWhereJsonContainsKey(string $column): static
164
    {
165
        return $this->whereJsonContainsKey($column);
166
    }
167
168
    /**
169
     * @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...
170
     */
171
    public function orWhereJsonContainsKey(string $column): static
172
    {
173
        $this->registerToken(
174
            'OR',
175
            [new CompileJsonContainsKey($column)],
176
            $this->whereTokens,
177
            $this->whereWrapper()
178
        );
179
180
        return $this;
181
    }
182
183
    /**
184
     * @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...
185
     */
186
    public function whereJsonDoesntContainKey(string $column): static
187
    {
188
        $this->registerToken(
189
            'AND',
190
            [new CompileJsonDoesntContainKey($column)],
191
            $this->whereTokens,
192
            $this->whereWrapper()
193
        );
194
195
        return $this;
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 andWhereJsonDoesntContainKey(string $column): static
202
    {
203
        return $this->whereJsonDoesntContainKey($column);
204
    }
205
206
    /**
207
     * @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...
208
     */
209
    public function orWhereJsonDoesntContainKey(string $column): static
210
    {
211
        $this->registerToken(
212
            'OR',
213
            [new CompileJsonDoesntContainKey($column)],
214
            $this->whereTokens,
215
            $this->whereWrapper()
216
        );
217
218
        return $this;
219
    }
220
221
    /**
222
     * @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...
223
     * @param int<0, max> $length
224
     * @param non-empty-string $operator
225
     */
226
    public function whereJsonLength(string $column, int $length, string $operator = '='): static
227
    {
228
        $this->registerToken(
229
            'AND',
230
            [new CompileJsonLength($column, $length, $operator)],
231
            $this->whereTokens,
232
            $this->whereWrapper()
233
        );
234
235
        return $this;
236
    }
237
238
    /**
239
     * @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...
240
     * @param int<0, max> $length
241
     * @param non-empty-string $operator
242
     */
243
    public function andWhereJsonLength(string $column, int $length, string $operator = '='): static
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
    public function orWhereJsonLength(string $column, int $length, string $operator = '='): static
254
    {
255
        $this->registerToken(
256
            'OR',
257
            [new CompileJsonLength($column, $length, $operator)],
258
            $this->whereTokens,
259
            $this->whereWrapper()
260
        );
261
262
        return $this;
263
    }
264
}
265