Having::havingIn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 3
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 Having
15
 * @package Qpdb\QueryBuilder\Traits
16
 * @property QueryStructure $queryStructure
17
 */
18
trait Having
19
{
20
21
	/**
22
	 * @param $field
23
	 * @param $value
24
	 * @param $glue
25
	 * @return $this
26
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
27
	 */
28
	public function havingEqual( $field, $value, $glue = 'AND' )
29
	{
30
		return $this->having( array( $field, $value, '=' ), $glue );
31
	}
32
33
	/**
34
	 * @param $field
35
	 * @param $value
36
	 * @return $this
37
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
38
	 */
39
	public function orHavingEqual( $field, $value )
40
	{
41
		return $this->having( array( $field, $value, '=' ), 'OR' );
42
	}
43
44
	/**
45
	 * @param $field
46
	 * @param $value
47
	 * @param string $glue
48
	 * @return $this
49
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
50
	 */
51
	public function havingNotEqual( $field, $value, $glue = 'AND' )
52
	{
53
		return $this->having( array( $field, $value, '<>' ), $glue );
54
	}
55
56
	/**
57
	 * @param $field
58
	 * @param $value
59
	 * @return $this
60
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
61
	 */
62
	public function orHavingNotEqual( $field, $value )
63
	{
64
		return $this->having( array( $field, $value, '<>' ), 'OR' );
65
	}
66
67
	/**
68
	 * @param $field
69
	 * @param $value
70
	 * @param string $glue
71
	 * @return $this
72
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
73
	 */
74
	public function havingLessThan( $field, $value, $glue = 'AND' )
75
	{
76
		return $this->having( array( $field, $value, '<' ), $glue );
77
	}
78
79
	/**
80
	 * @param $field
81
	 * @param $value
82
	 * @return $this
83
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
84
	 */
85
	public function orHavingLessThan( $field, $value )
86
	{
87
		return $this->having( array( $field, $value, '<' ), 'OR' );
88
	}
89
90
	/**
91
	 * @param $field
92
	 * @param $value
93
	 * @param string $glue
94
	 * @return $this
95
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
96
	 */
97
	public function havingLessThanOrEqual( $field, $value, $glue = 'AND' )
98
	{
99
		return $this->having( array( $field, $value, '<=' ), $glue );
100
	}
101
102
	/**
103
	 * @param $field
104
	 * @param $value
105
	 * @return $this
106
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
107
	 */
108
	public function orHavingLessThanOrEqual( $field, $value )
109
	{
110
		return $this->having( array( $field, $value, '<=' ), 'OR' );
111
	}
112
113
	/**
114
	 * @param $field
115
	 * @param $value
116
	 * @param string $glue
117
	 * @return $this
118
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
119
	 */
120
	public function havingGreaterThan( $field, $value, $glue = 'AND' )
121
	{
122
		return $this->having( array( $field, $value, '>' ), $glue );
123
	}
124
125
	/**
126
	 * @param $field
127
	 * @param $value
128
	 * @return $this
129
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
130
	 */
131
	public function orHavingGreaterThan( $field, $value )
132
	{
133
		return $this->having( array( $field, $value, '>' ), 'OR' );
134
	}
135
136
	/**
137
	 * @param $field
138
	 * @param $value
139
	 * @param string $glue
140
	 * @return $this
141
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
142
	 */
143
	public function havingGreaterThanOrEqual( $field, $value, $glue = 'AND' )
144
	{
145
		return $this->having( array( $field, $value, '>=' ), $glue );
146
	}
147
148
	/**
149
	 * @param $field
150
	 * @param $value
151
	 * @return $this
152
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
153
	 */
154
	public function orHavingGreaterThanOrEqual( $field, $value )
155
	{
156
		return $this->having( array( $field, $value, '>=' ), 'OR' );
157
	}
158
159
	/**
160
	 * @param $field
161
	 * @param $value
162
	 * @param string $glue
163
	 * @return $this
164
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
165
	 */
166
	public function havingLike( $field, $value, $glue = 'AND' )
167
	{
168
		return $this->having( array( $field, $value, 'LIKE' ), $glue );
169
	}
170
171
	/**
172
	 * @param $field
173
	 * @param $value
174
	 * @return $this
175
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
176
	 */
177
	public function orHavingLike( $field, $value )
178
	{
179
		return $this->having( array( $field, $value, 'LIKE' ), 'OR' );
180
	}
181
182
	/**
183
	 * @param $field
184
	 * @param $value
185
	 * @param string $glue
186
	 * @return $this
187
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
188
	 */
189
	public function havingNotLike( $field, $value, $glue = 'AND' )
190
	{
191
		return $this->having( array( $field, $value, 'NOT LIKE' ), $glue );
192
	}
193
194
	/**
195
	 * @param $field
196
	 * @param $value
197
	 * @return $this
198
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
199
	 */
200
	public function orHavingNotLike( $field, $value )
201
	{
202
		return $this->having( array( $field, $value, 'NOT LIKE' ), 'OR' );
203
	}
204
205
	/**
206
	 * @param $field
207
	 * @param $min
208
	 * @param $max
209
	 * @param string $glue
210
	 * @return $this
211
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
212
	 */
213
	public function havingBetween( $field, $min, $max, $glue = 'AND' )
214
	{
215
		return $this->having( array( $field, array( $min, $max ), 'BETWEEN' ), $glue );
216
	}
217
218
	/**
219
	 * @param $field
220
	 * @param $min
221
	 * @param $max
222
	 * @return $this
223
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
224
	 */
225
	public function orHavingBetween( $field, $min, $max )
226
	{
227
		return $this->having( array( $field, array( $min, $max ), 'BETWEEN' ), 'OR' );
228
	}
229
230
	/**
231
	 * @param $field
232
	 * @param $min
233
	 * @param $max
234
	 * @param string $glue
235
	 * @return $this
236
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
237
	 */
238
	public function havingNotBetween( $field, $min, $max, $glue = 'AND' )
239
	{
240
		return $this->having( array( $field, array( $min, $max ), 'NOT BETWEEN' ), $glue );
241
	}
242
243
	/**
244
	 * @param $field
245
	 * @param $min
246
	 * @param $max
247
	 * @return $this
248
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
249
	 */
250
	public function orHavingNotBetween( $field, $min, $max )
251
	{
252
		return $this->having( array( $field, array( $min, $max ), 'NOT BETWEEN' ), 'OR' );
253
	}
254
255
	/**
256
	 * @param $field
257
	 * @param $value
258
	 * @param string $glue
259
	 * @return $this
260
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
261
	 */
262
	public function havingIn( $field, $value, $glue = 'AND' )
263
	{
264
		return $this->having( array( $field, $value, 'IN' ), $glue );
265
	}
266
267
	/**
268
	 * @param $field
269
	 * @param $value
270
	 * @return $this
271
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
272
	 */
273
	public function orHavingIn( $field, $value )
274
	{
275
		return $this->having( array( $field, $value, 'IN' ), 'OR' );
276
	}
277
278
	/**
279
	 * @param $field
280
	 * @param $value
281
	 * @param string $glue
282
	 * @return $this
283
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
284
	 */
285
	public function havingNotIn( $field, $value, $glue = 'AND' )
286
	{
287
		return $this->having( array( $field, $value, 'NOT IN' ), $glue );
288
	}
289
290
	/**
291
	 * @param $field
292
	 * @param $value
293
	 * @return $this
294
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
295
	 */
296
	public function orHavingNotIn( $field, $value )
297
	{
298
		return $this->having( array( $field, $value, 'NOT IN' ), 'OR' );
299
	}
300
301
	/**
302
	 * @param $whereString
303
	 * @param array $bindParams
304
	 * @param string $glue
305
	 * @return $this
306
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
307
	 */
308
	public function havingExpression( $whereString, array $bindParams = [], $glue = 'AND' )
309
	{
310
		$whereString = $this->queryStructure->bindParamsExpression( $whereString, $bindParams );
311
312
		return $this->having( $whereString, $glue );
313
	}
314
315
	/**
316
	 * @param $whereString
317
	 * @param array $bindParams
318
	 * @return $this
319
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
320
	 */
321
	public function orHavingExpression( $whereString, array $bindParams = [] )
322
	{
323
		$whereString = $this->queryStructure->bindParamsExpression( $whereString, $bindParams );
324
325
		return $this->having( $whereString, 'OR' );
326
	}
327
328
	/**
329
	 * @return $this
330
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
331
	 */
332
	public function havingInvertResult()
333
	{
334
		$this->queryStructure->setElement( QueryStructure::HAVING_INVERT, 1 );
335
336
		return $this;
337
	}
338
339
	/**
340
	 * @param string $glue
341
	 * @return $this
342
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
343
	 */
344
	public function havingGroup( $glue = 'AND' )
345
	{
346
		$this->queryStructure->setElement( QueryStructure::HAVING, array( 'glue' => $glue, 'body' => '(', 'type' => 'start_where_group' ) );
347
348
		return $this;
349
	}
350
351
	/**
352
	 * @return $this
353
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
354
	 */
355
	public function orHavingGroup()
356
	{
357
		return $this->havingGroup( 'OR' );
358
	}
359
360
	/**
361
	 * @return $this
362
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
363
	 */
364
	public function havingGroupEnd()
365
	{
366
		$this->queryStructure->setElement( QueryStructure::HAVING, array( 'glue' => '', 'body' => ')', 'type' => 'end_where_group' ) );
367
368
		return $this;
369
	}
370
371
	/**
372
	 * @param $param
373
	 * @param string $glue
374
	 * @return $this
375
	 * @throws \Qpdb\QueryBuilder\Dependencies\QueryException
376
	 */
377
	private function having( $param, $glue = 'AND' )
378
	{
379
		return $this->createCondition( $param, $glue, QueryStructure::HAVING );
0 ignored issues
show
Bug introduced by
It seems like createCondition() 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

379
		return $this->/** @scrutinizer ignore-call */ createCondition( $param, $glue, QueryStructure::HAVING );
Loading history...
380
	}
381
382
}