Passed
Push — master ( ccfde0...23ae65 )
by Petr
09:08
created

Search::raw()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kalanis\kw_mapper\Search;
4
5
6
use kalanis\kw_mapper\Interfaces\IQueryBuilder;
7
use kalanis\kw_mapper\MapperException;
8
9
10
/**
11
 * Class Search
12
 * @package kalanis\kw_mapper\Search
13
 * Complex searching
14
 */
15
class Search extends ASearch
16
{
17
    /**
18
     * Property is not exact to the value
19
     * @param string $property
20
     * @param string|float|int $value
21
     * @throws MapperException
22
     * @return $this
23
     */
24 1
    public function notExact(string $property, $value): self
25
    {
26 1
        list($table, $column) = $this->parseProperty($property);
27 1
        $this->connector->notExact($table, $column, $value);
28 1
        return $this;
29
    }
30
31
    /**
32
     * Property is exact to the value
33
     * @param string $property
34
     * @param string|float|int $value
35
     * @throws MapperException
36
     * @return $this
37
     */
38 8
    public function exact(string $property, $value): self
39
    {
40 8
        list($table, $column) = $this->parseProperty($property);
41 8
        $this->connector->exact($table, $column, $value);
42 7
        return $this;
43
    }
44
45
    /**
46
     * @param string $property
47
     * @param string|float|int $value
48
     * @param bool $equals
49
     * @throws MapperException
50
     * @return $this
51
     */
52 1
    public function from(string $property, $value, bool $equals = true): self
53
    {
54 1
        list($table, $column) = $this->parseProperty($property);
55 1
        $this->connector->from($table, $column, $value, $equals);
56 1
        return $this;
57
    }
58
59
    /**
60
     * @param string $property
61
     * @param string|float|int $value
62
     * @param bool $equals
63
     * @throws MapperException
64
     * @return $this
65
     */
66 1
    public function to(string $property, $value, bool $equals = true): self
67
    {
68 1
        list($table, $column) = $this->parseProperty($property);
69 1
        $this->connector->to($table, $column, $value, $equals);
70 1
        return $this;
71
    }
72
73
    /**
74
     * Property is like value
75
     * @param string $property
76
     * @param string $value
77
     * @throws MapperException
78
     * @return $this
79
     */
80 7
    public function like(string $property, string $value): self
81
    {
82 7
        list($table, $column) = $this->parseProperty($property);
83 7
        $this->connector->like($table, $column, $value);
84 6
        return $this;
85
    }
86
87
    /**
88
     * Property is not like value
89
     * @param string $property
90
     * @param string $value
91
     * @throws MapperException
92
     * @return $this
93
     */
94 2
    public function notLike(string $property, string $value): self
95
    {
96 2
        list($table, $column) = $this->parseProperty($property);
97 2
        $this->connector->notLike($table, $column, $value);
98 2
        return $this;
99
    }
100
101
    /**
102
     * Property match regexp pattern - DATABASE DEPENDENT
103
     * @param string $property
104
     * @param string $pattern
105
     * @throws MapperException
106
     * @return $this
107
     */
108 1
    public function regexp(string $property, string $pattern): self
109
    {
110 1
        list($table, $column) = $this->parseProperty($property);
111 1
        $this->connector->regexp($table, $column, $pattern);
112 1
        return $this;
113
    }
114
115
    /**
116
     * Property is between values
117
     * @param string $property
118
     * @param string $min
119
     * @param string $max
120
     * @throws MapperException
121
     * @return $this
122
     */
123 1
    public function between(string $property, $min, $max): self
124
    {
125 1
        list($table, $column) = $this->parseProperty($property);
126 1
        $this->connector->between($table, $column, $min, $max);
127 1
        return $this;
128
    }
129
130
    /**
131
     * Property is null
132
     * @param string $property
133
     * @throws MapperException
134
     * @return $this
135
     */
136 1
    public function null(string $property): self
137
    {
138 1
        list($table, $column) = $this->parseProperty($property);
139 1
        $this->connector->null($table, $column);
140 1
        return $this;
141
    }
142
143
    /**
144
     * Property is not null
145
     * @param string $property
146
     * @throws MapperException
147
     * @return $this
148
     */
149 1
    public function notNull(string $property): self
150
    {
151 1
        list($table, $column) = $this->parseProperty($property);
152 1
        $this->connector->notNull($table, $column);
153 1
        return $this;
154
    }
155
156
    /**
157
     * Property is in values
158
     * @param string $property
159
     * @param array<string|int|float> $values
160
     * @throws MapperException
161
     * @return $this
162
     */
163 1
    public function in(string $property, array $values): self
164
    {
165 1
        list($table, $column) = $this->parseProperty($property);
166 1
        $this->connector->in($table, $column, $values);
167 1
        return $this;
168
    }
169
170
    /**
171
     * Property is not in values
172
     * @param string $property
173
     * @param array<string|int|float> $values
174
     * @throws MapperException
175
     * @return $this
176
     */
177 1
    public function notIn(string $property, array $values): self
178
    {
179 1
        list($table, $column) = $this->parseProperty($property);
180 1
        $this->connector->notIn($table, $column, $values);
181 1
        return $this;
182
    }
183
184
    /**
185
     * Raw query
186
     * Can pass some values as PDO params
187
     * Beware of used storage in Record - the query format depends on it!
188
     * @param string|string[]|callable $operation
189
     * @param string $prefix
190
     * @param mixed $values
191
     * @return $this
192
     */
193
    public function raw($operation, string $prefix = '', $values = null): self
194
    {
195
        $this->connector->raw($operation, $prefix, $values);
196
        return $this;
197
    }
198
199
    /**
200
     * Need fulfill all conditions
201
     * @return $this
202
     */
203 1
    public function useAnd(): self
204
    {
205 1
        $this->connector->useAnd();
206 1
        return $this;
207
    }
208
209
    /**
210
     * Need fulfill only one condition
211
     * @return $this
212
     */
213 1
    public function useOr(): self
214
    {
215 1
        $this->connector->useOr();
216 1
        return $this;
217
    }
218
219
    /**
220
     * Paging limit
221
     * @param int|null $limit
222
     * @return $this
223
     */
224 1
    public function limit(?int $limit): self
225
    {
226 1
        $this->connector->limit($limit);
227 1
        return $this;
228
    }
229
230
    /**
231
     * Paging offset
232
     * @param int|null $offset
233
     * @return $this
234
     */
235 1
    public function offset(?int $offset): self
236
    {
237 1
        $this->connector->offset($offset);
238 1
        return $this;
239
    }
240
241
    /**
242
     * Add ordering by property
243
     * @param string $property
244
     * @param string $direction
245
     * @throws MapperException
246
     * @return $this
247
     */
248 1
    public function orderBy(string $property, string $direction = IQueryBuilder::ORDER_ASC): self
249
    {
250 1
        list($table, $column) = $this->parseProperty($property);
251 1
        $this->connector->orderBy($table, $column, $direction);
252 1
        return $this;
253
    }
254
255
    /**
256
     * Add grouping by property
257
     * @param string $property
258
     * @throws MapperException
259
     * @return $this
260
     */
261 1
    public function groupBy(string $property): self
262
    {
263 1
        list($table, $column) = $this->parseProperty($property);
264 1
        $this->connector->groupBy($table, $column);
265 1
        return $this;
266
    }
267
268
    /**
269
     * Add child which will be mounted to the results
270
     * @param string $childAlias
271
     * @param string $joinType
272
     * @param string $parentAlias
273
     * @param string $customAlias
274
     * @throws MapperException
275
     * @return $this
276
     */
277 8
    public function child(string $childAlias, string $joinType = IQueryBuilder::JOIN_LEFT, string $parentAlias = '', string $customAlias = ''): self
278
    {
279 8
        $this->connector->child($childAlias, $joinType, $parentAlias, $customAlias);
280 3
        return $this;
281
    }
282
283
    /**
284
     * That child is not set for chosen parent
285
     * @param string $childAlias
286
     * @param string $property
287
     * @throws MapperException
288
     * @return $this
289
     */
290 3
    public function childNotExist(string $childAlias, string $property): self
291
    {
292 3
        list($table, $column) = $this->parseProperty($property);
293 3
        $this->connector->childNotExist($childAlias, $table, $column);
294 1
        return $this;
295
    }
296
}
297