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

WhereJsonTrait   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 236
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 79
c 1
b 0
f 0
dl 0
loc 236
rs 10
wmc 18

18 Methods

Rating   Name   Duplication   Size   Complexity  
A andWhereJson() 0 3 1
A whereJson() 0 10 1
A andWhereJsonDoesntContainKey() 0 3 1
A andWhereJsonLength() 0 3 1
A whereJsonContainsKey() 0 10 1
A whereJsonContains() 0 10 1
A orWhereJsonLength() 0 10 1
A andWhereJsonContainsKey() 0 3 1
A whereJsonDoesntContainKey() 0 10 1
A orWhereJsonDoesntContain() 0 10 1
A whereJsonDoesntContain() 0 10 1
A orWhereJson() 0 10 1
A andWhereJsonDoesntContain() 0 3 1
A orWhereJsonContainsKey() 0 10 1
A orWhereJsonContains() 0 10 1
A whereJsonLength() 0 10 1
A orWhereJsonDoesntContainKey() 0 10 1
A andWhereJsonContains() 0 3 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\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): self
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): self
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): self
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
     */
69
    public function whereJsonContains(string $column, mixed $value): self
70
    {
71
        $this->registerToken(
72
            'AND',
73
            [new CompileJsonContains($column, $value)],
74
            $this->whereTokens,
75
            $this->whereWrapper()
76
        );
77
78
        return $this;
79
    }
80
81
    /**
82
     * @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...
83
     */
84
    public function andWhereJsonContains(string $column, mixed $value): self
85
    {
86
        return $this->whereJsonContains($column, $value);
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
    public function orWhereJsonContains(string $column, mixed $value): self
93
    {
94
        $this->registerToken(
95
            'OR',
96
            [new CompileJsonContains($column, $value)],
97
            $this->whereTokens,
98
            $this->whereWrapper()
99
        );
100
101
        return $this;
102
    }
103
104
    /**
105
     * @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...
106
     */
107
    public function whereJsonDoesntContain(string $column, mixed $value): self
108
    {
109
        $this->registerToken(
110
            'AND',
111
            [new CompileJsonDoesntContain($column, $value)],
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
     */
122
    public function andWhereJsonDoesntContain(string $column, mixed $value): self
123
    {
124
        return $this->whereJsonDoesntContain($column, $value);
125
    }
126
127
    /**
128
     * @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...
129
     */
130
    public function orWhereJsonDoesntContain(string $column, mixed $value): self
131
    {
132
        $this->registerToken(
133
            'OR',
134
            [new CompileJsonDoesntContain($column, $value)],
135
            $this->whereTokens,
136
            $this->whereWrapper()
137
        );
138
139
        return $this;
140
    }
141
142
    /**
143
     * @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...
144
     */
145
    public function whereJsonContainsKey(string $column): self
146
    {
147
        $this->registerToken(
148
            'AND',
149
            [new CompileJsonContainsKey($column)],
150
            $this->whereTokens,
151
            $this->whereWrapper()
152
        );
153
154
        return $this;
155
    }
156
157
    /**
158
     * @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...
159
     */
160
    public function andWhereJsonContainsKey(string $column): self
161
    {
162
        return $this->whereJsonContainsKey($column);
163
    }
164
165
    /**
166
     * @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...
167
     */
168
    public function orWhereJsonContainsKey(string $column): self
169
    {
170
        $this->registerToken(
171
            'OR',
172
            [new CompileJsonContainsKey($column)],
173
            $this->whereTokens,
174
            $this->whereWrapper()
175
        );
176
177
        return $this;
178
    }
179
180
    /**
181
     * @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...
182
     */
183
    public function whereJsonDoesntContainKey(string $column): self
184
    {
185
        $this->registerToken(
186
            'AND',
187
            [new CompileJsonDoesntContainKey($column)],
188
            $this->whereTokens,
189
            $this->whereWrapper()
190
        );
191
192
        return $this;
193
    }
194
195
    /**
196
     * @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...
197
     *
198
     * @return $this|self
199
     */
200
    public function andWhereJsonDoesntContainKey(string $column): self
201
    {
202
        return $this->whereJsonDoesntContainKey($column);
203
    }
204
205
    /**
206
     * @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...
207
     */
208
    public function orWhereJsonDoesntContainKey(string $column): self
209
    {
210
        $this->registerToken(
211
            'OR',
212
            [new CompileJsonDoesntContainKey($column)],
213
            $this->whereTokens,
214
            $this->whereWrapper()
215
        );
216
217
        return $this;
218
    }
219
220
    /**
221
     * @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...
222
     * @param int<0, max> $length
223
     * @param non-empty-string $operator
224
     */
225
    public function whereJsonLength(string $column, int $length, string $operator = '='): self
226
    {
227
        $this->registerToken(
228
            'AND',
229
            [new CompileJsonLength($column, $length, $operator)],
230
            $this->whereTokens,
231
            $this->whereWrapper()
232
        );
233
234
        return $this;
235
    }
236
237
    /**
238
     * @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...
239
     * @param int<0, max> $length
240
     * @param non-empty-string $operator
241
     */
242
    public function andWhereJsonLength(string $column, int $length, string $operator = '='): self
243
    {
244
        return $this->whereJsonLength($column, $length, $operator);
245
    }
246
247
    /**
248
     * @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...
249
     * @param int<0, max> $length
250
     * @param non-empty-string $operator
251
     */
252
    public function orWhereJsonLength(string $column, int $length, string $operator = '='): self
253
    {
254
        $this->registerToken(
255
            'OR',
256
            [new CompileJsonLength($column, $length, $operator)],
257
            $this->whereTokens,
258
            $this->whereWrapper()
259
        );
260
261
        return $this;
262
    }
263
}
264