Completed
Push — 2.x ( 6c47ee...c394f3 )
by Aleksei
24s queued 15s
created

WhereJsonTrait   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 204
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 73
dl 0
loc 204
rs 10
c 1
b 0
f 0
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A whereJson() 0 10 1
A whereJsonContainsKey() 0 10 1
A whereJsonContains() 0 10 1
A orWhereJsonLength() 0 10 1
A whereJsonDoesntContainKey() 0 10 1
A orWhereJsonDoesntContain() 0 14 1
A whereJsonDoesntContain() 0 14 1
A orWhereJson() 0 10 1
A orWhereJsonContainsKey() 0 10 1
A orWhereJsonContains() 0 14 1
A whereJsonLength() 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\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 orWhereJson(string $column, mixed $value): static
47
    {
48
        $this->registerToken(
49
            'OR',
50
            [new CompileJson($column), $value],
51
            $this->whereTokens,
52
            $this->whereWrapper()
53
        );
54
55
        return $this;
56
    }
57
58
    /**
59
     * @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...
60
     * @param bool $encode Encode the value into JSON. It is not used in this driver.
61
     * @param bool $validate Check that $value is a valid JSON string if the $encode parameter is false. It is not used in this driver.
62
     */
63
    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

63
    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

63
    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...
64
    {
65
        $this->registerToken(
66
            'AND',
67
            [new CompileJsonContains($column, $value)],
68
            $this->whereTokens,
69
            $this->whereWrapper()
70
        );
71
72
        return $this;
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. It is not used in this driver.
78
     * @param bool $validate Check that $value is a valid JSON string if the $encode parameter is false. It is not used in this driver.
79
     */
80
    public function orWhereJsonContains(
81
        string $column,
82
        mixed $value,
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
        $this->registerToken(
87
            'OR',
88
            [new CompileJsonContains($column, $value)],
89
            $this->whereTokens,
90
            $this->whereWrapper()
91
        );
92
93
        return $this;
94
    }
95
96
    /**
97
     * @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...
98
     * @param bool $encode Encode the value into JSON. It is not used in this driver.
99
     * @param bool $validate Check that $value is a valid JSON string if the $encode parameter is false. It is not used in this driver.
100
     */
101
    public function whereJsonDoesntContain(
102
        string $column,
103
        mixed $value,
104
        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

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

105
        /** @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...
106
    ): static {
107
        $this->registerToken(
108
            'AND',
109
            [new CompileJsonDoesntContain($column, $value)],
110
            $this->whereTokens,
111
            $this->whereWrapper()
112
        );
113
114
        return $this;
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. It is not used in this driver.
120
     * @param bool $validate Check that $value is a valid JSON string if the $encode parameter is false. It is not used in this driver.
121
     */
122
    public function orWhereJsonDoesntContain(
123
        string $column,
124
        mixed $value,
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
        $this->registerToken(
129
            'OR',
130
            [new CompileJsonDoesntContain($column, $value)],
131
            $this->whereTokens,
132
            $this->whereWrapper()
133
        );
134
135
        return $this;
136
    }
137
138
    /**
139
     * @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...
140
     */
141
    public function whereJsonContainsKey(string $column): static
142
    {
143
        $this->registerToken(
144
            'AND',
145
            [new CompileJsonContainsKey($column)],
146
            $this->whereTokens,
147
            $this->whereWrapper()
148
        );
149
150
        return $this;
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
     */
156
    public function orWhereJsonContainsKey(string $column): static
157
    {
158
        $this->registerToken(
159
            'OR',
160
            [new CompileJsonContainsKey($column)],
161
            $this->whereTokens,
162
            $this->whereWrapper()
163
        );
164
165
        return $this;
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 whereJsonDoesntContainKey(string $column): static
172
    {
173
        $this->registerToken(
174
            'AND',
175
            [new CompileJsonDoesntContainKey($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 orWhereJsonDoesntContainKey(string $column): static
187
    {
188
        $this->registerToken(
189
            'OR',
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
     * @param int<0, max> $length
201
     * @param non-empty-string $operator
202
     */
203
    public function whereJsonLength(string $column, int $length, string $operator = '='): static
204
    {
205
        $this->registerToken(
206
            'AND',
207
            [new CompileJsonLength($column, $length, $operator)],
208
            $this->whereTokens,
209
            $this->whereWrapper()
210
        );
211
212
        return $this;
213
    }
214
215
    /**
216
     * @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...
217
     * @param int<0, max> $length
218
     * @param non-empty-string $operator
219
     */
220
    public function orWhereJsonLength(string $column, int $length, string $operator = '='): static
221
    {
222
        $this->registerToken(
223
            'OR',
224
            [new CompileJsonLength($column, $length, $operator)],
225
            $this->whereTokens,
226
            $this->whereWrapper()
227
        );
228
229
        return $this;
230
    }
231
}
232