Passed
Pull Request — 2.x (#135)
by Maxim
17:48
created

WhereJsonTrait   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 230
Duplicated Lines 0 %

Importance

Changes 5
Bugs 2 Features 0
Metric Value
eloc 59
c 5
b 2
f 0
dl 0
loc 230
rs 10
wmc 18

18 Methods

Rating   Name   Duplication   Size   Complexity  
A andWhereJson() 0 3 1
A whereJson() 0 10 1
A whereJsonDoesntContainKey() 0 10 1
A orWhereJsonDoesntContain() 0 7 1
A orWhereJsonLength() 0 10 1
A andWhereJsonContainsKey() 0 3 1
A andWhereJsonDoesntContain() 0 7 1
A orWhereJsonContains() 0 3 1
A whereJsonContainsKey() 0 10 1
A whereJsonDoesntContain() 0 7 1
A andWhereJsonLength() 0 3 1
A andWhereJsonDoesntContainKey() 0 3 1
A orWhereJson() 0 10 1
A whereJsonContains() 0 3 1
A andWhereJsonContains() 0 3 1
A whereJsonLength() 0 10 1
A orWhereJsonContainsKey() 0 10 1
A orWhereJsonDoesntContainKey() 0 10 1
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): 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
    public function andWhereJson(string $column, mixed $value): self
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): self
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): 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

70
    public function whereJsonContains(string $column, /** @scrutinizer ignore-unused */ mixed $value, bool $encode = true, bool $validate = true): 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 $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): 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 $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): 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

70
    public function whereJsonContains(/** @scrutinizer ignore-unused */ string $column, mixed $value, bool $encode = true, bool $validate = true): 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...
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(string $column, mixed $value, bool $encode = true, bool $validate = true): 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

80
    public function andWhereJsonContains(string $column, /** @scrutinizer ignore-unused */ mixed $value, bool $encode = true, bool $validate = true): 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

80
    public function andWhereJsonContains(/** @scrutinizer ignore-unused */ string $column, mixed $value, bool $encode = true, bool $validate = true): 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 $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

80
    public function andWhereJsonContains(string $column, mixed $value, bool $encode = true, /** @scrutinizer ignore-unused */ bool $validate = true): 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 $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

80
    public function andWhereJsonContains(string $column, mixed $value, /** @scrutinizer ignore-unused */ bool $encode = true, bool $validate = true): 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...
81
    {
82
        throw new DriverException('This database engine does not support JSON contains operations.');
83
    }
84
85
    /**
86
     * @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...
87
     * @param bool $encode Encode the value into JSON.
88
     * @param bool $validate Checking the value that it is valid JSON.
89
     */
90
    public function orWhereJsonContains(string $column, mixed $value, bool $encode = true, bool $validate = true): self
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

90
    public function orWhereJsonContains(string $column, mixed $value, bool $encode = true, /** @scrutinizer ignore-unused */ bool $validate = true): 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 $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

90
    public function orWhereJsonContains(string $column, mixed $value, /** @scrutinizer ignore-unused */ bool $encode = true, bool $validate = true): 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

90
    public function orWhereJsonContains(string $column, /** @scrutinizer ignore-unused */ mixed $value, bool $encode = true, bool $validate = true): 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

90
    public function orWhereJsonContains(/** @scrutinizer ignore-unused */ string $column, mixed $value, bool $encode = true, bool $validate = true): 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...
91
    {
92
        throw new DriverException('This database engine does not support JSON contains operations.');
93
    }
94
95
    /**
96
     * @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...
97
     * @param bool $encode Encode the value into JSON.
98
     * @param bool $validate Checking the value that it is valid JSON.
99
     */
100
    public function whereJsonDoesntContain(
101
        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

101
        /** @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...
102
        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

102
        /** @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...
103
        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

103
        /** @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...
104
        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

104
        /** @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...
105
    ): self {
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
     * @param bool $encode Encode the value into JSON.
112
     * @param bool $validate Checking the value that it is valid JSON.
113
     */
114
    public function andWhereJsonDoesntContain(
115
        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

115
        /** @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...
116
        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

116
        /** @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...
117
        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

117
        /** @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...
118
        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

118
        /** @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...
119
    ): self {
120
        throw new DriverException('This database engine does not support JSON contains operations.');
121
    }
122
123
    /**
124
     * @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...
125
     * @param bool $encode Encode the value into JSON.
126
     * @param bool $validate Checking the value that it is valid JSON.
127
     */
128
    public function orWhereJsonDoesntContain(
129
        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

129
        /** @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...
130
        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

130
        /** @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...
131
        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

131
        /** @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...
132
        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

132
        /** @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...
133
    ): self {
134
        throw new DriverException('This database engine does not support JSON contains operations.');
135
    }
136
137
    /**
138
     * @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...
139
     */
140
    public function whereJsonContainsKey(string $column): self
141
    {
142
        $this->registerToken(
143
            'AND',
144
            [new CompileJsonContainsKey($column)],
145
            $this->whereTokens,
146
            $this->whereWrapper()
147
        );
148
149
        return $this;
150
    }
151
152
    /**
153
     * @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...
154
     */
155
    public function andWhereJsonContainsKey(string $column): self
156
    {
157
        return $this->whereJsonContainsKey($column);
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 orWhereJsonContainsKey(string $column): self
164
    {
165
        $this->registerToken(
166
            'OR',
167
            [new CompileJsonContainsKey($column)],
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 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
    public function andWhereJsonDoesntContainKey(string $column): self
194
    {
195
        return $this->whereJsonDoesntContainKey($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 orWhereJsonDoesntContainKey(string $column): self
202
    {
203
        $this->registerToken(
204
            'OR',
205
            [new CompileJsonDoesntContainKey($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
     * @param int<0, max> $length
216
     * @param non-empty-string $operator
217
     */
218
    public function whereJsonLength(string $column, int $length, string $operator = '='): self
219
    {
220
        $this->registerToken(
221
            'AND',
222
            [new CompileJsonLength($column, $length, $operator)],
223
            $this->whereTokens,
224
            $this->whereWrapper()
225
        );
226
227
        return $this;
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
     * @param int<0, max> $length
233
     * @param non-empty-string $operator
234
     */
235
    public function andWhereJsonLength(string $column, int $length, string $operator = '='): self
236
    {
237
        return $this->whereJsonLength($column, $length, $operator);
238
    }
239
240
    /**
241
     * @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...
242
     * @param int<0, max> $length
243
     * @param non-empty-string $operator
244
     */
245
    public function orWhereJsonLength(string $column, int $length, string $operator = '='): self
246
    {
247
        $this->registerToken(
248
            'OR',
249
            [new CompileJsonLength($column, $length, $operator)],
250
            $this->whereTokens,
251
            $this->whereWrapper()
252
        );
253
254
        return $this;
255
    }
256
}
257