Passed
Pull Request — 2.x (#135)
by Maxim
19:43
created

WhereJsonTrait::orWhereJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 2
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\CompileJsonLength;
17
use Cycle\Database\Exception\DriverException;
18
19
/**
20
 * @internal
21
 */
22
trait WhereJsonTrait
23
{
24
    /**
25
     * @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...
26
     *
27
     * @return $this|self
28
     */
29
    public function whereJson(string $column, mixed $value): self
30
    {
31
        $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

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

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

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

73
    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...
74
    {
75
        throw new DriverException('This database engine does not support JSON contains operations.');
76
    }
77
78
    /**
79
     * @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...
80
     *
81
     * @return $this|self
82
     */
83
    public function andWhereJsonContains(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

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

83
    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...
84
    {
85
        throw new DriverException('This database engine does not support JSON contains operations.');
86
    }
87
88
    /**
89
     * @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...
90
     *
91
     * @return $this|self
92
     */
93
    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

93
    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

93
    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...
94
    {
95
        throw new DriverException('This database engine does not support JSON contains operations.');
96
    }
97
98
    /**
99
     * @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...
100
     *
101
     * @return $this|self
102
     */
103
    public function whereJsonDoesntContain(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

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

103
    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...
104
    {
105
        throw new DriverException('This database engine does not support JSON contains operations.');
106
    }
107
108
    /**
109
     * @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...
110
     *
111
     * @return $this|self
112
     */
113
    public function andWhereJsonDoesntContain(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

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

113
    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...
114
    {
115
        throw new DriverException('This database engine does not support JSON contains operations.');
116
    }
117
118
    /**
119
     * @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...
120
     *
121
     * @return $this|self
122
     */
123
    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

123
    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

123
    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...
124
    {
125
        throw new DriverException('This database engine does not support JSON contains operations.');
126
    }
127
128
    /**
129
     * @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...
130
     *
131
     * @return $this|self
132
     */
133
    public function whereJsonContainsKey(string $column): self
134
    {
135
        $this->registerToken(
136
            'AND',
137
            [new CompileJsonContainsKey($column)],
138
            $this->whereTokens,
139
            $this->whereWrapper()
140
        );
141
142
        return $this;
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
     * @return $this|self
149
     */
150
    public function andWhereJsonContainsKey(string $column): self
151
    {
152
        return $this->whereJsonContainsKey($column);
153
    }
154
155
    /**
156
     * @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...
157
     *
158
     * @return $this|self
159
     */
160
    public function orWhereJsonContainsKey(string $column): self
161
    {
162
        $this->registerToken(
163
            'OR',
164
            [new CompileJsonContainsKey($column)],
165
            $this->whereTokens,
166
            $this->whereWrapper()
167
        );
168
169
        return $this;
170
    }
171
172
    /**
173
     * @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...
174
     * @param 0|positive-int $length
175
     * @param non-empty-string $operator
176
     *
177
     * @return $this|self
178
     */
179
    public function whereJsonLength(string $column, int $length, string $operator = '='): self
180
    {
181
        $this->registerToken(
182
            'AND',
183
            [new CompileJsonLength($column, $length, $operator)],
184
            $this->whereTokens,
185
            $this->whereWrapper()
186
        );
187
188
        return $this;
189
    }
190
191
    /**
192
     * @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...
193
     * @param 0|positive-int $length
194
     * @param non-empty-string $operator
195
     *
196
     * @return $this|self
197
     */
198
    public function andWhereJsonLength(string $column, int $length, string $operator = '='): self
199
    {
200
        return $this->whereJsonLength($column, $length, $operator);
201
    }
202
203
    /**
204
     * @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...
205
     * @param 0|positive-int $length
206
     * @param non-empty-string $operator
207
     *
208
     * @return $this|self
209
     */
210
    public function orWhereJsonLength(string $column, int $length, string $operator = '='): self
211
    {
212
        $this->registerToken(
213
            'OR',
214
            [new CompileJsonLength($column, $length, $operator)],
215
            $this->whereTokens,
216
            $this->whereWrapper()
217
        );
218
219
        return $this;
220
    }
221
}
222