Passed
Push — master ( 793cce...b0cf56 )
by Eugene
07:19
created

Criteria::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
/**
4
 * This file is part of the tarantool/client package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Tarantool\Client\Schema;
15
16
final class Criteria
17
{
18
    /** @var int|string */
19
    private $index = 0;
20
21
    /** @var array<int, mixed> */
22
    private $key = [];
23
24
    /** @var int */
25
    private $limit = \PHP_INT_MAX & 0xffffffff;
26
27
    /** @var int */
28
    private $offset = 0;
29
30
    /** @psalm-var null|IteratorTypes::* */
31
    private $iteratorType;
32
33
    private function __construct()
34
    {
35
    }
36
37
    /**
38
     * @param int|string $index
39
     */
40 21
    public static function index($index) : self
41
    {
42 21
        $self = new self();
43 21
        $self->index = $index;
44
45 21
        return $self;
46
    }
47
48
    /**
49
     * @param int|string $index
50
     */
51 190
    public function andIndex($index) : self
52
    {
53 190
        $new = clone $this;
54 190
        $new->index = $index;
55
56 190
        return $new;
57
    }
58
59
    /**
60
     * @return int|string
61
     */
62 202
    public function getIndex()
63
    {
64 202
        return $this->index;
65
    }
66
67 199
    public static function key(array $key) : self
68
    {
69 199
        $self = new self();
70 199
        $self->key = $key;
71
72 199
        return $self;
73
    }
74
75 6
    public function andKey(array $key) : self
76
    {
77 6
        $new = clone $this;
78 6
        $new->key = $key;
79
80 6
        return $new;
81
    }
82
83 199
    public function getKey() : array
84
    {
85 199
        return $this->key;
86
    }
87
88 6
    public static function limit(int $limit) : self
89
    {
90 6
        $self = new self();
91 6
        $self->limit = $limit;
92
93 6
        return $self;
94
    }
95
96 3
    public function andLimit(int $limit) : self
97
    {
98 3
        $new = clone $this;
99 3
        $new->limit = $limit;
100
101 3
        return $new;
102
    }
103
104 196
    public function getLimit() : int
105
    {
106 196
        return $this->limit;
107
    }
108
109 6
    public static function offset(int $offset) : self
110
    {
111 6
        $self = new self();
112 6
        $self->offset = $offset;
113
114 6
        return $self;
115
    }
116
117 3
    public function andOffset(int $offset) : self
118
    {
119 3
        $new = clone $this;
120 3
        $new->offset = $offset;
121
122 3
        return $new;
123
    }
124
125 196
    public function getOffset() : int
126
    {
127 196
        return $this->offset;
128
    }
129
130
    /**
131
     * @psalm-param IteratorTypes::* $iteratorType
132
     */
133 78
    public static function iterator(int $iteratorType) : self
134
    {
135 78
        $self = new self();
136 78
        $self->iteratorType = $iteratorType;
137
138 78
        return $self;
139
    }
140
141
    /**
142
     * @psalm-param IteratorTypes::* $iteratorType
143
     */
144 39
    public function andIterator(int $iteratorType) : self
145
    {
146 39
        $new = clone $this;
147 39
        $new->iteratorType = $iteratorType;
148
149 39
        return $new;
150
    }
151
152 36
    public static function eqIterator() : self
153
    {
154 36
        return self::iterator(IteratorTypes::EQ);
155
    }
156
157 3
    public function andEqIterator() : self
158
    {
159 3
        return $this->andIterator(IteratorTypes::EQ);
160
    }
161
162 3
    public static function reqIterator() : self
163
    {
164 3
        return self::iterator(IteratorTypes::REQ);
165
    }
166
167 3
    public function andReqIterator() : self
168
    {
169 3
        return $this->andIterator(IteratorTypes::REQ);
170
    }
171
172 6
    public static function allIterator() : self
173
    {
174 6
        return self::iterator(IteratorTypes::ALL);
175
    }
176
177 3
    public function andAllIterator() : self
178
    {
179 3
        return $this->andIterator(IteratorTypes::ALL);
180
    }
181
182 3
    public static function ltIterator() : self
183
    {
184 3
        return self::iterator(IteratorTypes::LT);
185
    }
186
187 3
    public function andLtIterator() : self
188
    {
189 3
        return $this->andIterator(IteratorTypes::LT);
190
    }
191
192 3
    public static function leIterator() : self
193
    {
194 3
        return self::iterator(IteratorTypes::LE);
195
    }
196
197 3
    public function andLeIterator() : self
198
    {
199 3
        return $this->andIterator(IteratorTypes::LE);
200
    }
201
202 3
    public static function geIterator() : self
203
    {
204 3
        return self::iterator(IteratorTypes::GE);
205
    }
206
207 3
    public function andGeIterator() : self
208
    {
209 3
        return $this->andIterator(IteratorTypes::GE);
210
    }
211
212 3
    public static function gtIterator() : self
213
    {
214 3
        return self::iterator(IteratorTypes::GT);
215
    }
216
217 3
    public function andGtIterator() : self
218
    {
219 3
        return $this->andIterator(IteratorTypes::GT);
220
    }
221
222 3
    public static function bitsAllSetIterator() : self
223
    {
224 3
        return self::iterator(IteratorTypes::BITS_ALL_SET);
225
    }
226
227 3
    public function andBitsAllSetIterator() : self
228
    {
229 3
        return $this->andIterator(IteratorTypes::BITS_ALL_SET);
230
    }
231
232 3
    public static function bitsAnySetIterator() : self
233
    {
234 3
        return self::iterator(IteratorTypes::BITS_ANY_SET);
235
    }
236
237 3
    public function andBitsAnySetIterator() : self
238
    {
239 3
        return $this->andIterator(IteratorTypes::BITS_ANY_SET);
240
    }
241
242 3
    public static function bitsAllNotSetIterator() : self
243
    {
244 3
        return self::iterator(IteratorTypes::BITS_ALL_NOT_SET);
245
    }
246
247 3
    public function andBitsAllNotSetIterator() : self
248
    {
249 3
        return $this->andIterator(IteratorTypes::BITS_ALL_NOT_SET);
250
    }
251
252 3
    public static function overlapsIterator() : self
253
    {
254 3
        return self::iterator(IteratorTypes::OVERLAPS);
255
    }
256
257 3
    public function andOverlapsIterator() : self
258
    {
259 3
        return $this->andIterator(IteratorTypes::OVERLAPS);
260
    }
261
262 3
    public static function neighborIterator() : self
263
    {
264 3
        return self::iterator(IteratorTypes::NEIGHBOR);
265
    }
266
267 3
    public function andNeighborIterator() : self
268
    {
269 3
        return $this->andIterator(IteratorTypes::NEIGHBOR);
270
    }
271
272
    /**
273
     * @psalm-return IteratorTypes::*
274
     */
275 271
    public function getIterator() : int
276
    {
277 271
        if (null !== $this->iteratorType) {
278 81
            return $this->iteratorType;
279
        }
280
281 193
        return $this->key ? IteratorTypes::EQ : IteratorTypes::ALL;
282
    }
283
}
284