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

WhereJsonTrait::whereJsonLength()   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 3
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\CompileJsonLength;
16
use Cycle\Database\Exception\DriverException;
17
18
/**
19
 * @internal
20
 */
21
trait WhereJsonTrait
22
{
23
    /**
24
     * @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...
25
     *
26
     * @return $this|self
27
     */
28
    public function whereJson(string $column, mixed $value): self
29
    {
30
        $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

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

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

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

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

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

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

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

102
    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

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

112
    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

112
    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...
113
    {
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
     *
120
     * @return $this|self
121
     */
122
    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

122
    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

122
    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...
123
    {
124
        throw new DriverException('This database engine does not support JSON contains operations.');
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
     * @param 0|positive-int $length
130
     * @param non-empty-string $operator
131
     *
132
     * @return $this|self
133
     */
134
    public function whereJsonLength(string $column, int $length, string $operator = '='): self
135
    {
136
        $this->registerToken(
137
            'AND',
138
            [new CompileJsonLength($column, $length, $operator)],
139
            $this->whereTokens,
140
            $this->whereWrapper()
141
        );
142
143
        return $this;
144
    }
145
146
    /**
147
     * @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...
148
     * @param 0|positive-int $length
149
     * @param non-empty-string $operator
150
     *
151
     * @return $this|self
152
     */
153
    public function andWhereJsonLength(string $column, int $length, string $operator = '='): self
154
    {
155
        return $this->whereJsonLength($column, $length, $operator);
156
    }
157
158
    /**
159
     * @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...
160
     * @param 0|positive-int $length
161
     * @param non-empty-string $operator
162
     *
163
     * @return $this|self
164
     */
165
    public function orWhereJsonLength(string $column, int $length, string $operator = '='): self
166
    {
167
        $this->registerToken(
168
            'OR',
169
            [new CompileJsonLength($column, $length, $operator)],
170
            $this->whereTokens,
171
            $this->whereWrapper()
172
        );
173
174
        return $this;
175
    }
176
}
177