Where::whereGroupEnd()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * Author: Adrian Dumitru
5
 * Date: 4/25/2017 1:13 AM
6
 */
7
8
namespace Qpdb\QueryBuilder\Traits;
9
10
11
use Qpdb\QueryBuilder\Dependencies\QueryStructure;
12
13
/**
14
 * Trait Where
15
 * @package Qpdb\QueryBuilder\Traits
16
 * @property QueryStructure $queryStructure
17
 */
18
trait Where
19
{
20
21
	/**
22
	 * @param $field
23
	 * @param $value
24
	 * @param $glue
25
	 * @return $this
26
	 */
27
	public function whereEqual( $field, $value, $glue = 'AND' )
28
	{
29
		return $this->where( array( $field, $value, '=' ), $glue );
30
	}
31
32
	/**
33
	 * @param $field
34
	 * @param $value
35
	 * @return $this
36
	 */
37
	public function orWhereEqual( $field, $value )
38
	{
39
		return $this->where( array( $field, $value, '=' ), 'OR' );
40
	}
41
42
	/**
43
	 * @param $field
44
	 * @param $value
45
	 * @param string $glue
46
	 * @return $this
47
	 */
48
	public function whereNotEqual( $field, $value, $glue = 'AND' )
49
	{
50
		return $this->where( array( $field, $value, '<>' ), $glue );
51
	}
52
53
	/**
54
	 * @param $field
55
	 * @param $value
56
	 * @return $this
57
	 */
58
	public function orWhereNotEqual( $field, $value )
59
	{
60
		return $this->where( array( $field, $value, '<>' ), 'OR' );
61
	}
62
63
	/**
64
	 * @param $field
65
	 * @param $value
66
	 * @param string $glue
67
	 * @return $this
68
	 */
69
	public function whereLessThan( $field, $value, $glue = 'AND' )
70
	{
71
		return $this->where( array( $field, $value, '<' ), $glue );
72
	}
73
74
	/**
75
	 * @param $field
76
	 * @param $value
77
	 * @return $this
78
	 */
79
	public function orWhereLessThan( $field, $value )
80
	{
81
		return $this->where( array( $field, $value, '<' ), 'OR' );
82
	}
83
84
	/**
85
	 * @param $field
86
	 * @param $value
87
	 * @param string $glue
88
	 * @return $this
89
	 */
90
	public function whereLessThanOrEqual( $field, $value, $glue = 'AND' )
91
	{
92
		return $this->where( array( $field, $value, '<=' ), $glue );
93
	}
94
95
	/**
96
	 * @param $field
97
	 * @param $value
98
	 * @return $this
99
	 */
100
	public function orWhereLessThanOrEqual( $field, $value )
101
	{
102
		return $this->where( array( $field, $value, '<=' ), 'OR' );
103
	}
104
105
	/**
106
	 * @param $field
107
	 * @param $value
108
	 * @param string $glue
109
	 * @return $this
110
	 */
111
	public function whereGreaterThan( $field, $value, $glue = 'AND' )
112
	{
113
		return $this->where( array( $field, $value, '>' ), $glue );
114
	}
115
116
	/**
117
	 * @param $field
118
	 * @param $value
119
	 * @return $this
120
	 */
121
	public function orWhereGreaterThan( $field, $value )
122
	{
123
		return $this->where( array( $field, $value, '>' ), 'OR' );
124
	}
125
126
	/**
127
	 * @param $field
128
	 * @param $value
129
	 * @param string $glue
130
	 * @return $this
131
	 */
132
	public function whereGreaterThanOrEqual( $field, $value, $glue = 'AND' )
133
	{
134
		return $this->where( array( $field, $value, '>=' ), $glue );
135
	}
136
137
	/**
138
	 * @param $field
139
	 * @param $value
140
	 * @return $this
141
	 */
142
	public function orWhereGreaterThanOrEqual( $field, $value )
143
	{
144
		return $this->where( array( $field, $value, '>=' ), 'OR' );
145
	}
146
147
	/**
148
	 * @param $field
149
	 * @param $value
150
	 * @param string $glue
151
	 * @return $this
152
	 */
153
	public function whereLike( $field, $value, $glue = 'AND' )
154
	{
155
		return $this->where( array( $field, $value, 'LIKE' ), $glue );
156
	}
157
158
	/**
159
	 * @param $field
160
	 * @param $value
161
	 * @return $this
162
	 */
163
	public function orWhereLike( $field, $value )
164
	{
165
		return $this->where( array( $field, $value, 'LIKE' ), 'OR' );
166
	}
167
168
	/**
169
	 * @param $field
170
	 * @param $value
171
	 * @param string $glue
172
	 * @return $this
173
	 */
174
	public function whereNotLike( $field, $value, $glue = 'AND' )
175
	{
176
		return $this->where( array( $field, $value, 'NOT LIKE' ), $glue );
177
	}
178
179
	/**
180
	 * @param $field
181
	 * @param $value
182
	 * @return $this
183
	 */
184
	public function orWhereNotLike( $field, $value )
185
	{
186
		return $this->where( array( $field, $value, 'NOT LIKE' ), 'OR' );
187
	}
188
189
	/**
190
	 * @param $field
191
	 * @param $min
192
	 * @param $max
193
	 * @param string $glue
194
	 * @return $this
195
	 */
196
	public function whereBetween( $field, $min, $max, $glue = 'AND' )
197
	{
198
		return $this->where( array( $field, array( $min, $max ), 'BETWEEN' ), $glue );
199
	}
200
201
	/**
202
	 * @param $field
203
	 * @param $min
204
	 * @param $max
205
	 * @return $this
206
	 */
207
	public function orWhereBetween( $field, $min, $max )
208
	{
209
		return $this->where( array( $field, array( $min, $max ), 'BETWEEN' ), 'OR' );
210
	}
211
212
	/**
213
	 * @param $field
214
	 * @param $min
215
	 * @param $max
216
	 * @param string $glue
217
	 * @return $this
218
	 */
219
	public function whereNotBetween( $field, $min, $max, $glue = 'AND' )
220
	{
221
		return $this->where( array( $field, array( $min, $max ), 'NOT BETWEEN' ), $glue );
222
	}
223
224
	/**
225
	 * @param $field
226
	 * @param $min
227
	 * @param $max
228
	 * @return $this
229
	 */
230
	public function orWhereNotBetween( $field, $min, $max )
231
	{
232
		return $this->where( array( $field, array( $min, $max ), 'NOT BETWEEN' ), 'OR' );
233
	}
234
235
	/**
236
	 * @param $field
237
	 * @param $value
238
	 * @param string $glue
239
	 * @return $this
240
	 */
241
	public function whereIn( $field, $value, $glue = 'AND' )
242
	{
243
		return $this->where( array( $field, $value, 'IN' ), $glue );
244
	}
245
246
	/**
247
	 * @param $field
248
	 * @param $value
249
	 * @return $this
250
	 */
251
	public function orWhereIn( $field, $value )
252
	{
253
		return $this->where( array( $field, $value, 'IN' ), 'OR' );
254
	}
255
256
	/**
257
	 * @param $field
258
	 * @param $value
259
	 * @param string $glue
260
	 * @return $this
261
	 */
262
	public function whereNotIn( $field, $value, $glue = 'AND' )
263
	{
264
		return $this->where( array( $field, $value, 'NOT IN' ), $glue );
265
	}
266
267
	/**
268
	 * @param $field
269
	 * @param $value
270
	 * @return $this
271
	 */
272
	public function orWhereNotIn( $field, $value )
273
	{
274
		return $this->where( array( $field, $value, 'NOT IN' ), 'OR' );
275
	}
276
277
	/**
278
	 * @param $whereString
279
	 * @param array $bindParams
280
	 * @param string $glue
281
	 * @return $this
282
	 */
283
	public function whereExpression( $whereString, array $bindParams = [], $glue = 'AND' )
284
	{
285
		$whereString = $this->queryStructure->bindParamsExpression( $whereString, $bindParams );
286
287
		return $this->where( $whereString, $glue );
288
	}
289
290
	/**
291
	 * @param $whereString
292
	 * @param array $bindParams
293
	 * @return $this
294
	 */
295
	public function orWhereExpression( $whereString, array $bindParams = [] )
296
	{
297
		$whereString = $this->queryStructure->bindParamsExpression( $whereString, $bindParams );
298
299
		return $this->where( $whereString, 'OR' );
300
	}
301
302
	/**
303
	 * @return $this
304
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
305
	 */
306
	public function whereInvertResult()
307
	{
308
		$this->queryStructure->setElement( QueryStructure::WHERE_INVERT, 1 );
309
310
		return $this;
311
	}
312
313
	/**
314
	 * @param string $glue
315
	 * @return $this
316
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
317
	 */
318
	public function whereGroup( $glue = 'AND' )
319
	{
320
		$this->queryStructure->setElement( QueryStructure::WHERE, array( 'glue' => $glue, 'body' => '(', 'type' => 'start_where_group' ) );
321
322
		return $this;
323
	}
324
325
	/**
326
	 * @return $this
327
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
328
	 */
329
	public function orWhereGroup()
330
	{
331
		return $this->whereGroup( 'OR' );
332
	}
333
334
	/**
335
	 * @return $this
336
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
337
	 */
338
	public function whereGroupEnd()
339
	{
340
		$this->queryStructure->setElement( QueryStructure::WHERE, array( 'glue' => '', 'body' => ')', 'type' => 'end_where_group' ) );
341
342
		return $this;
343
	}
344
345
	/**
346
	 * @return $this
347
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
348
	 */
349
	public function ignoreWhereTrigger()
350
	{
351
		$this->queryStructure->setElement( QueryStructure::WHERE_TRIGGER, 0 );
352
353
		return $this;
354
	}
355
356
357
	/**
358
	 * @param string|array $param
359
	 * @param string $glue
360
	 * @return $this
361
	 */
362
	private function where( $param, $glue = 'AND' )
363
	{
364
		return $this->/** @scrutinizer ignore-call */
365
		createCondition( $param, $glue, QueryStructure::WHERE );
366
	}
367
368
}