Passed
Push — master ( de41c9...cdffbf )
by Eugene
03:06
created

Criteria::andLeIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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