Completed
Push — master ( f1b67b...f961dc )
by recca
01:39
created

BuildsQueries   D

Complexity

Total Complexity 73

Size/Duplication

Total Lines 1052
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 98.63%

Importance

Changes 0
Metric Value
dl 0
loc 1052
ccs 216
cts 219
cp 0.9863
rs 4.9402
c 0
b 0
f 0
wmc 73
lcom 1
cbo 1

73 Methods

Rating   Name   Duplication   Size   Complexity  
A select() 0 6 1
A selectRaw() 0 6 1
A selectSub() 0 6 1
A addSelect() 0 6 1
A distinct() 0 6 1
A from() 0 6 1
A join() 0 6 1
A joinWhere() 0 6 1
A leftJoin() 0 6 1
A leftJoinWhere() 0 6 1
A rightJoin() 0 6 1
A rightJoinWhere() 0 6 1
A crossJoin() 0 6 1
A mergeWheres() 0 6 1
A tap() 0 6 1
A where() 0 6 1
A orWhere() 0 6 1
A whereColumn() 0 6 1
A orWhereColumn() 0 6 1
A whereRaw() 0 6 1
A orWhereRaw() 0 6 1
A whereIn() 0 6 1
A orWhereIn() 0 6 1
A whereNotIn() 0 6 1
A orWhereNotIn() 0 6 1
A whereNull() 0 6 1
A orWhereNull() 0 6 1
A whereNotNull() 0 6 1
A whereBetween() 0 6 1
A orWhereBetween() 0 6 1
A whereNotBetween() 0 6 1
A orWhereNotBetween() 0 6 1
A orWhereNotNull() 0 6 1
A whereDate() 0 6 1
A orWhereDate() 0 6 1
A whereTime() 0 6 1
A orWhereTime() 0 6 1
A whereDay() 0 6 1
A whereMonth() 0 6 1
A whereYear() 0 6 1
A whereNested() 0 6 1
A addNestedWhereQuery() 0 6 1
A whereExists() 0 6 1
A orWhereExists() 0 6 1
A whereNotExists() 0 6 1
A orWhereNotExists() 0 6 1
A addWhereExistsQuery() 0 6 1
A dynamicWhere() 0 6 1
A groupBy() 0 6 1
A having() 0 6 1
A orHaving() 0 6 1
A havingRaw() 0 6 1
A orHavingRaw() 0 6 1
A orderBy() 0 6 1
A orderByDesc() 0 6 1
A latest() 0 6 1
A oldest() 0 6 1
A inRandomOrder() 0 6 1
A orderByRaw() 0 6 1
A skip() 0 6 1
A offset() 0 6 1
A take() 0 6 1
A limit() 0 6 1
A forPage() 0 6 1
A forPageAfterId() 0 6 1
A union() 0 6 1
A unionAll() 0 6 1
A lock() 0 6 1
A lockForUpdate() 0 6 1
A sharedLock() 0 6 1
A when() 0 6 1
A unless() 0 6 1
A useWritePdo() 0 6 1

How to fix   Complexity   

Complex Class

Complex classes like BuildsQueries often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use BuildsQueries, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Recca0120\Repository\Concerns;
4
5
use Closure;
6
use Recca0120\Repository\Method;
7
use Illuminate\Database\Query\Builder;
8
9
trait BuildsQueries
10
{
11
    /**
12
     * Set the columns to be selected.
13
     *
14
     * @param  array|mixed  $columns
15
     * @return $this
16
     */
17 1
    public function select($columns = ['*'])
18
    {
19 1
        $this->methods[] = new Method(__FUNCTION__, [$columns]);
0 ignored issues
show
Bug introduced by
The property methods does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
20
21 1
        return $this;
22
    }
23
24
    /**
25
     * Add a new "raw" select expression to the query.
26
     *
27
     * @param  string  $expression
28
     * @param  array   $bindings
29
     * @return $this
30
     */
31 1
    public function selectRaw($expression, array $bindings = [])
32
    {
33 1
        $this->methods[] = new Method(__FUNCTION__, [$expression, $bindings]);
34
35 1
        return $this;
36
    }
37
38
    /**
39
     * Add a subselect expression to the query.
40
     *
41
     * @param  \Closure|\Illuminate\Database\Query\Builder|string $query
42
     * @param  string  $as
43
     * @return $this
44
     *
45
     * @throws \InvalidArgumentException
46
     */
47 1
    public function selectSub($query, $as)
48
    {
49 1
        $this->methods[] = new Method(__FUNCTION__, [$query, $as]);
50
51 1
        return $this;
52
    }
53
54
    /**
55
     * Add a new select column to the query.
56
     *
57
     * @param  array|mixed  $column
58
     * @return $this
59
     */
60 1
    public function addSelect($column)
61
    {
62 1
        $this->methods[] = new Method(__FUNCTION__, [$column]);
63
64 1
        return $this;
65
    }
66
67
    /**
68
     * Force the query to only return distinct results.
69
     *
70
     * @return $this
71
     */
72 1
    public function distinct()
73
    {
74 1
        $this->methods[] = new Method(__FUNCTION__);
75
76 1
        return $this;
77
    }
78
79
    /**
80
     * Set the table which the query is targeting.
81
     *
82
     * @param  string  $table
83
     * @return $this
84
     */
85 1
    public function from($table)
86
    {
87 1
        $this->methods[] = new Method(__FUNCTION__, [$table]);
88
89 1
        return $this;
90
    }
91
92
    /**
93
     * Add a join clause to the query.
94
     *
95
     * @param  string  $table
96
     * @param  string  $first
97
     * @param  string  $operator
98
     * @param  string  $second
99
     * @param  string  $type
100
     * @param  bool    $where
101
     * @return $this
102
     */
103 1
    public function join($table, $first, $operator = null, $second = null, $type = 'inner', $where = false)
104
    {
105 1
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second, $type, $where]);
106
107 1
        return $this;
108
    }
109
110
    /**
111
     * Add a "join where" clause to the query.
112
     *
113
     * @param  string  $table
114
     * @param  string  $first
115
     * @param  string  $operator
116
     * @param  string  $second
117
     * @param  string  $type
118
     * @return $this
119
     */
120 1
    public function joinWhere($table, $first, $operator, $second, $type = 'inner')
121
    {
122 1
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second, $type]);
123
124 1
        return $this;
125
    }
126
127
    /**
128
     * Add a left join to the query.
129
     *
130
     * @param  string  $table
131
     * @param  string  $first
132
     * @param  string  $operator
133
     * @param  string  $second
134
     * @return $this
135
     */
136 1
    public function leftJoin($table, $first, $operator = null, $second = null)
137
    {
138 1
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second]);
139
140 1
        return $this;
141
    }
142
143
    /**
144
     * Add a "join where" clause to the query.
145
     *
146
     * @param  string  $table
147
     * @param  string  $first
148
     * @param  string  $operator
149
     * @param  string  $second
150
     * @return $this
151
     */
152 1
    public function leftJoinWhere($table, $first, $operator, $second)
153
    {
154 1
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second]);
155
156 1
        return $this;
157
    }
158
159
    /**
160
     * Add a right join to the query.
161
     *
162
     * @param  string  $table
163
     * @param  string  $first
164
     * @param  string  $operator
165
     * @param  string  $second
166
     * @return $this
167
     */
168 1
    public function rightJoin($table, $first, $operator = null, $second = null)
169
    {
170 1
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second]);
171
172 1
        return $this;
173
    }
174
175
    /**
176
     * Add a "right join where" clause to the query.
177
     *
178
     * @param  string  $table
179
     * @param  string  $first
180
     * @param  string  $operator
181
     * @param  string  $second
182
     * @return $this
183
     */
184 1
    public function rightJoinWhere($table, $first, $operator, $second)
185
    {
186 1
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second]);
187
188 1
        return $this;
189
    }
190
191
    /**
192
     * Add a "cross join" clause to the query.
193
     *
194
     * @param  string  $table
195
     * @param  string  $first
196
     * @param  string  $operator
197
     * @param  string  $second
198
     * @return $this
199
     */
200 1
    public function crossJoin($table, $first = null, $operator = null, $second = null)
201
    {
202 1
        $this->methods[] = new Method(__FUNCTION__, [$table, $first, $operator, $second]);
203
204 1
        return $this;
205
    }
206
207
    /**
208
     * Merge an array of where clauses and bindings.
209
     *
210
     * @param  array  $wheres
211
     * @param  array  $bindings
212
     * @return void
213
     */
214
    public function mergeWheres($wheres, $bindings)
215
    {
216
        $this->methods[] = new Method(__FUNCTION__, [$wheres, $bindings]);
217
218
        return $this;
219
    }
220
221
    /**
222
     * Pass the query to a given callback.
223
     *
224
     * @param  \Closure  $callback
225
     * @return $this
226
     */
227 1
    public function tap($callback)
228
    {
229 1
        $this->methods[] = new Method(__FUNCTION__, [$callback]);
230
231 1
        return $this;
232
    }
233
234
    /**
235
     * Add a basic where clause to the query.
236
     *
237
     * @param  string|array|\Closure  $column
238
     * @param  string  $operator
239
     * @param  mixed   $value
240
     * @param  string  $boolean
241
     * @return $this
242
     */
243 12
    public function where($column, $operator = null, $value = null, $boolean = 'and')
244
    {
245 12
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
246
247 12
        return $this;
248
    }
249
250
    /**
251
     * Add an "or where" clause to the query.
252
     *
253
     * @param  \Closure|string  $column
254
     * @param  string  $operator
255
     * @param  mixed   $value
256
     * @return $this
257
     */
258 1
    public function orWhere($column, $operator = null, $value = null)
259
    {
260 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value]);
261
262 1
        return $this;
263
    }
264
265
    /**
266
     * Add a "where" clause comparing two columns to the query.
267
     *
268
     * @param  string|array  $first
269
     * @param  string|null  $operator
270
     * @param  string|null  $second
271
     * @param  string|null  $boolean
272
     * @return $this
273
     */
274 1
    public function whereColumn($first, $operator = null, $second = null, $boolean = 'and')
275
    {
276 1
        $this->methods[] = new Method(__FUNCTION__, [$first, $operator, $second, $boolean]);
277
278 1
        return $this;
279
    }
280
281
    /**
282
     * Add an "or where" clause comparing two columns to the query.
283
     *
284
     * @param  string|array  $first
285
     * @param  string|null  $operator
286
     * @param  string|null  $second
287
     * @return $this
288
     */
289 1
    public function orWhereColumn($first, $operator = null, $second = null)
290
    {
291 1
        $this->methods[] = new Method(__FUNCTION__, [$first, $operator, $second]);
292
293 1
        return $this;
294
    }
295
296
    /**
297
     * Add a raw where clause to the query.
298
     *
299
     * @param  string  $sql
300
     * @param  mixed   $bindings
301
     * @param  string  $boolean
302
     * @return $this
303
     */
304 1
    public function whereRaw($sql, $bindings = [], $boolean = 'and')
305
    {
306 1
        $this->methods[] = new Method(__FUNCTION__, [$sql, $bindings, $boolean]);
307
308 1
        return $this;
309
    }
310
311
    /**
312
     * Add a raw or where clause to the query.
313
     *
314
     * @param  string  $sql
315
     * @param  array   $bindings
316
     * @return $this
317
     */
318 1
    public function orWhereRaw($sql, array $bindings = [])
319
    {
320 1
        $this->methods[] = new Method(__FUNCTION__, [$sql, $bindings]);
321
322 1
        return $this;
323
    }
324
325
    /**
326
     * Add a "where in" clause to the query.
327
     *
328
     * @param  string  $column
329
     * @param  mixed   $values
330
     * @param  string  $boolean
331
     * @param  bool    $not
332
     * @return $this
333
     */
334 3
    public function whereIn($column, $values, $boolean = 'and', $not = false)
335
    {
336 3
        $this->methods[] = new Method(__FUNCTION__, [$column, $values, $boolean, $not]);
337
338 3
        return $this;
339
    }
340
341
    /**
342
     * Add an "or where in" clause to the query.
343
     *
344
     * @param  string  $column
345
     * @param  mixed   $values
346
     * @return $this
347
     */
348 2
    public function orWhereIn($column, $values)
349
    {
350 2
        $this->methods[] = new Method(__FUNCTION__, [$column, $values]);
351
352 2
        return $this;
353
    }
354
355
    /**
356
     * Add a "where not in" clause to the query.
357
     *
358
     * @param  string  $column
359
     * @param  mixed   $values
360
     * @param  string  $boolean
361
     * @return $this
362
     */
363 1
    public function whereNotIn($column, $values, $boolean = 'and')
364
    {
365 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $values, $boolean]);
366
367 1
        return $this;
368
    }
369
370
    /**
371
     * Add an "or where not in" clause to the query.
372
     *
373
     * @param  string  $column
374
     * @param  mixed   $values
375
     * @return $this
376
     */
377 1
    public function orWhereNotIn($column, $values)
378
    {
379 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $values]);
380
381 1
        return $this;
382
    }
383
384
    /**
385
     * Add a "where null" clause to the query.
386
     *
387
     * @param  string  $column
388
     * @param  string  $boolean
389
     * @param  bool    $not
390
     * @return $this
391
     */
392 1
    public function whereNull($column, $boolean = 'and', $not = false)
393
    {
394 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $boolean, $not]);
395
396 1
        return $this;
397
    }
398
399
    /**
400
     * Add an "or where null" clause to the query.
401
     *
402
     * @param  string  $column
403
     * @return $this
404
     */
405 1
    public function orWhereNull($column)
406
    {
407 1
        $this->methods[] = new Method(__FUNCTION__, [$column]);
408
409 1
        return $this;
410
    }
411
412
    /**
413
     * Add a "where not null" clause to the query.
414
     *
415
     * @param  string  $column
416
     * @param  string  $boolean
417
     * @return $this
418
     */
419 1
    public function whereNotNull($column, $boolean = 'and')
420
    {
421 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $boolean]);
422
423 1
        return $this;
424
    }
425
426
    /**
427
     * Add a where between statement to the query.
428
     *
429
     * @param  string  $column
430
     * @param  array   $values
431
     * @param  string  $boolean
432
     * @param  bool  $not
433
     * @return $this
434
     */
435 3
    public function whereBetween($column, array $values, $boolean = 'and', $not = false)
436
    {
437 3
        $this->methods[] = new Method(__FUNCTION__, [$column, $values, $boolean, $not]);
438
439 3
        return $this;
440
    }
441
442
    /**
443
     * Add an or where between statement to the query.
444
     *
445
     * @param  string  $column
446
     * @param  array   $values
447
     * @return $this
448
     */
449 1
    public function orWhereBetween($column, array $values)
450
    {
451 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $values]);
452
453 1
        return $this;
454
    }
455
456
    /**
457
     * Add a where not between statement to the query.
458
     *
459
     * @param  string  $column
460
     * @param  array   $values
461
     * @param  string  $boolean
462
     * @return $this
463
     */
464 1
    public function whereNotBetween($column, array $values, $boolean = 'and')
465
    {
466 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $values, $boolean]);
467
468 1
        return $this;
469
    }
470
471
    /**
472
     * Add an or where not between statement to the query.
473
     *
474
     * @param  string  $column
475
     * @param  array   $values
476
     * @return $this
477
     */
478 1
    public function orWhereNotBetween($column, array $values)
479
    {
480 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $values]);
481
482 1
        return $this;
483
    }
484
485
    /**
486
     * Add an "or where not null" clause to the query.
487
     *
488
     * @param  string  $column
489
     * @return $this
490
     */
491 1
    public function orWhereNotNull($column)
492
    {
493 1
        $this->methods[] = new Method(__FUNCTION__, [$column]);
494
495 1
        return $this;
496
    }
497
498
    /**
499
     * Add a "where date" statement to the query.
500
     *
501
     * @param  string  $column
502
     * @param  string  $operator
503
     * @param  mixed  $value
504
     * @param  string  $boolean
505
     * @return $this
506
     */
507 1
    public function whereDate($column, $operator, $value = null, $boolean = 'and')
508
    {
509 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
510
511 1
        return $this;
512
    }
513
514
    /**
515
     * Add an "or where date" statement to the query.
516
     *
517
     * @param  string  $column
518
     * @param  string  $operator
519
     * @param  string  $value
520
     * @return $this
521
     */
522 1
    public function orWhereDate($column, $operator, $value)
523
    {
524 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value]);
525
526 1
        return $this;
527
    }
528
529
    /**
530
     * Add a "where time" statement to the query.
531
     *
532
     * @param  string  $column
533
     * @param  string   $operator
534
     * @param  int   $value
535
     * @param  string   $boolean
536
     * @return $this
537
     */
538 1
    public function whereTime($column, $operator, $value, $boolean = 'and')
539
    {
540 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
541
542 1
        return $this;
543
    }
544
545
    /**
546
     * Add an "or where time" statement to the query.
547
     *
548
     * @param  string  $column
549
     * @param  string   $operator
550
     * @param  int   $value
551
     * @return $this
552
     */
553 1
    public function orWhereTime($column, $operator, $value)
554
    {
555 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value]);
556
557 1
        return $this;
558
    }
559
560
    /**
561
     * Add a "where day" statement to the query.
562
     *
563
     * @param  string  $column
564
     * @param  string  $operator
565
     * @param  mixed  $value
566
     * @param  string  $boolean
567
     * @return $this
568
     */
569 1
    public function whereDay($column, $operator, $value = null, $boolean = 'and')
570
    {
571 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
572
573 1
        return $this;
574
    }
575
576
    /**
577
     * Add a "where month" statement to the query.
578
     *
579
     * @param  string  $column
580
     * @param  string  $operator
581
     * @param  mixed  $value
582
     * @param  string  $boolean
583
     * @return $this
584
     */
585 1
    public function whereMonth($column, $operator, $value = null, $boolean = 'and')
586
    {
587 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
588
589 1
        return $this;
590
    }
591
592
    /**
593
     * Add a "where year" statement to the query.
594
     *
595
     * @param  string  $column
596
     * @param  string  $operator
597
     * @param  mixed  $value
598
     * @param  string  $boolean
599
     * @return $this
600
     */
601 1
    public function whereYear($column, $operator, $value = null, $boolean = 'and')
602
    {
603 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
604
605 1
        return $this;
606
    }
607
608
    /**
609
     * Add a nested where statement to the query.
610
     *
611
     * @param  \Closure $callback
612
     * @param  string   $boolean
613
     * @return $this
614
     */
615 1
    public function whereNested(Closure $callback, $boolean = 'and')
616
    {
617 1
        $this->methods[] = new Method(__FUNCTION__, [$callback, $boolean]);
618
619 1
        return $this;
620
    }
621
622
    /**
623
     * Add another query builder as a nested where to the query builder.
624
     *
625
     * @param  $this $query
0 ignored issues
show
introduced by
The type BuildsQueries for parameter $query is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?
Loading history...
626
     * @param  string  $boolean
627
     * @return $this
628
     */
629 1
    public function addNestedWhereQuery($query, $boolean = 'and')
630
    {
631 1
        $this->methods[] = new Method(__FUNCTION__, [$query, $boolean]);
632
633 1
        return $this;
634
    }
635
636
    /**
637
     * Add an exists clause to the query.
638
     *
639
     * @param  \Closure $callback
640
     * @param  string   $boolean
641
     * @param  bool     $not
642
     * @return $this
643
     */
644 1
    public function whereExists(Closure $callback, $boolean = 'and', $not = false)
645
    {
646 1
        $this->methods[] = new Method(__FUNCTION__, [$callback, $boolean, $not]);
647
648 1
        return $this;
649
    }
650
651
    /**
652
     * Add an or exists clause to the query.
653
     *
654
     * @param  \Closure $callback
655
     * @param  bool     $not
656
     * @return $this
657
     */
658 1
    public function orWhereExists(Closure $callback, $not = false)
659
    {
660 1
        $this->methods[] = new Method(__FUNCTION__, [$callback, $not]);
661
662 1
        return $this;
663
    }
664
665
    /**
666
     * Add a where not exists clause to the query.
667
     *
668
     * @param  \Closure $callback
669
     * @param  string   $boolean
670
     * @return $this
671
     */
672 1
    public function whereNotExists(Closure $callback, $boolean = 'and')
673
    {
674 1
        $this->methods[] = new Method(__FUNCTION__, [$callback, $boolean]);
675
676 1
        return $this;
677
    }
678
679
    /**
680
     * Add a where not exists clause to the query.
681
     *
682
     * @param  \Closure  $callback
683
     * @return $this
684
     */
685 1
    public function orWhereNotExists(Closure $callback)
686
    {
687 1
        $this->methods[] = new Method(__FUNCTION__, [$callback]);
688
689 1
        return $this;
690
    }
691
692
    /**
693
     * Add an exists clause to the query.
694
     *
695
     * @param  \Illuminate\Database\Query\Builder $query
696
     * @param  string  $boolean
697
     * @param  bool  $not
698
     * @return $this
699
     */
700 1
    public function addWhereExistsQuery(Builder $query, $boolean = 'and', $not = false)
701
    {
702 1
        $this->methods[] = new Method(__FUNCTION__, [$query, $boolean, $not]);
703
704 1
        return $this;
705
    }
706
707
    /**
708
     * Handles dynamic "where" clauses to the query.
709
     *
710
     * @param  string  $method
711
     * @param  string  $parameters
712
     * @return $this
713
     */
714 2
    public function dynamicWhere($method, $parameters)
715
    {
716 2
        $this->methods[] = new Method(__FUNCTION__, [$method, $parameters]);
717
718 2
        return $this;
719
    }
720
721
    /**
722
     * Add a "group by" clause to the query.
723
     *
724
     * @param  array  ...$groups
725
     * @return $this
726
     */
727 1
    public function groupBy()
728
    {
729 1
        $this->methods[] = new Method(__FUNCTION__, func_get_args());
730
731 1
        return $this;
732
    }
733
734
    /**
735
     * Add a "having" clause to the query.
736
     *
737
     * @param  string  $column
738
     * @param  string  $operator
739
     * @param  string  $value
740
     * @param  string  $boolean
741
     * @return $this
742
     */
743 1
    public function having($column, $operator = null, $value = null, $boolean = 'and')
744
    {
745 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value, $boolean]);
746
747 1
        return $this;
748
    }
749
750
    /**
751
     * Add a "or having" clause to the query.
752
     *
753
     * @param  string  $column
754
     * @param  string  $operator
755
     * @param  string  $value
756
     * @return $this
757
     */
758 1
    public function orHaving($column, $operator = null, $value = null)
759
    {
760 1
        $this->methods[] = new Method(__FUNCTION__, [$column, $operator, $value]);
761
762 1
        return $this;
763
    }
764
765
    /**
766
     * Add a raw having clause to the query.
767
     *
768
     * @param  string  $sql
769
     * @param  array   $bindings
770
     * @param  string  $boolean
771
     * @return $this
772
     */
773 1
    public function havingRaw($sql, array $bindings = [], $boolean = 'and')
774
    {
775 1
        $this->methods[] = new Method(__FUNCTION__, [$sql, $bindings, $boolean]);
776
777 1
        return $this;
778
    }
779
780
    /**
781
     * Add a raw or having clause to the query.
782
     *
783
     * @param  string  $sql
784
     * @param  array   $bindings
785
     * @return $this
786
     */
787 1
    public function orHavingRaw($sql, array $bindings = [])
788
    {
789 1
        $this->methods[] = new Method(__FUNCTION__, [$sql, $bindings]);
790
791 1
        return $this;
792
    }
793
794
    /**
795
     * Add an "order by" clause to the query.
796
     *
797
     * @param  string  $column
798
     * @param  string  $direction
799
     * @return $this
800
     */
801 4
    public function orderBy($column, $direction = 'asc')
802
    {
803 4
        $this->methods[] = new Method(__FUNCTION__, [$column, $direction]);
804
805 4
        return $this;
806
    }
807
808
    /**
809
     * Add a descending "order by" clause to the query.
810
     *
811
     * @param  string  $column
812
     * @return $this
813
     */
814 1
    public function orderByDesc($column)
815
    {
816 1
        $this->methods[] = new Method(__FUNCTION__, [$column]);
817
818 1
        return $this;
819
    }
820
821
    /**
822
     * Add an "order by" clause for a timestamp to the query.
823
     *
824
     * @param  string  $column
825
     * @return $this
826
     */
827 1
    public function latest($column = 'created_at')
828
    {
829 1
        $this->methods[] = new Method(__FUNCTION__, [$column]);
830
831 1
        return $this;
832
    }
833
834
    /**
835
     * Add an "order by" clause for a timestamp to the query.
836
     *
837
     * @param  string  $column
838
     * @return $this
839
     */
840 1
    public function oldest($column = 'created_at')
841
    {
842 1
        $this->methods[] = new Method(__FUNCTION__, [$column]);
843
844 1
        return $this;
845
    }
846
847
    /**
848
     * Put the query's results in random order.
849
     *
850
     * @param  string  $seed
851
     * @return $this
852
     */
853 1
    public function inRandomOrder($seed = '')
854
    {
855 1
        $this->methods[] = new Method(__FUNCTION__, [$seed]);
856
857 1
        return $this;
858
    }
859
860
    /**
861
     * Add a raw "order by" clause to the query.
862
     *
863
     * @param  string  $sql
864
     * @param  array  $bindings
865
     * @return $this
866
     */
867 1
    public function orderByRaw($sql, $bindings = [])
868
    {
869 1
        $this->methods[] = new Method(__FUNCTION__, [$sql, $bindings]);
870
871 1
        return $this;
872
    }
873
874
    /**
875
     * Alias to set the "offset" value of the query.
876
     *
877
     * @param  int  $value
878
     * @return $this
879
     */
880 1
    public function skip($value)
881
    {
882 1
        $this->methods[] = new Method(__FUNCTION__, [$value]);
883
884 1
        return $this;
885
    }
886
887
    /**
888
     * Set the "offset" value of the query.
889
     *
890
     * @param  int  $value
891
     * @return $this
892
     */
893 1
    public function offset($value)
894
    {
895 1
        $this->methods[] = new Method(__FUNCTION__, [$value]);
896
897 1
        return $this;
898
    }
899
900
    /**
901
     * Alias to set the "limit" value of the query.
902
     *
903
     * @param  int  $value
904
     * @return $this
905
     */
906 1
    public function take($value)
907
    {
908 1
        $this->methods[] = new Method(__FUNCTION__, [$value]);
909
910 1
        return $this;
911
    }
912
913
    /**
914
     * Set the "limit" value of the query.
915
     *
916
     * @param  int  $value
917
     * @return $this
918
     */
919 1
    public function limit($value)
920
    {
921 1
        $this->methods[] = new Method(__FUNCTION__, [$value]);
922
923 1
        return $this;
924
    }
925
926
    /**
927
     * Set the limit and offset for a given page.
928
     *
929
     * @param  int  $page
930
     * @param  int  $perPage
931
     * @return $this
932
     */
933 1
    public function forPage($page, $perPage = 15)
934
    {
935 1
        $this->methods[] = new Method(__FUNCTION__, [$page, $perPage]);
936
937 1
        return $this;
938
    }
939
940
    /**
941
     * Constrain the query to the next "page" of results after a given ID.
942
     *
943
     * @param  int  $perPage
944
     * @param  int  $lastId
945
     * @param  string  $column
946
     * @return $this
947
     */
948 1
    public function forPageAfterId($perPage = 15, $lastId = 0, $column = 'id')
949
    {
950 1
        $this->methods[] = new Method(__FUNCTION__, [$perPage, $lastId, $column]);
951
952 1
        return $this;
953
    }
954
955
    /**
956
     * Add a union statement to the query.
957
     *
958
     * @param  \Illuminate\Database\Query\Builder|\Closure  $query
959
     * @param  bool  $all
960
     * @return $this
961
     */
962 1
    public function union($query, $all = false)
963
    {
964 1
        $this->methods[] = new Method(__FUNCTION__, [$query, $all]);
965
966 1
        return $this;
967
    }
968
969
    /**
970
     * Add a union all statement to the query.
971
     *
972
     * @param  \Illuminate\Database\Query\Builder|\Closure  $query
973
     * @return $this
974
     */
975 1
    public function unionAll($query)
976
    {
977 1
        $this->methods[] = new Method(__FUNCTION__, [$query]);
978
979 1
        return $this;
980
    }
981
982
    /**
983
     * Lock the selected rows in the table.
984
     *
985
     * @param  string|bool  $value
986
     * @return $this
987
     */
988 1
    public function lock($value = true)
989
    {
990 1
        $this->methods[] = new Method(__FUNCTION__, [$value]);
991
992 1
        return $this;
993
    }
994
995
    /**
996
     * Lock the selected rows in the table for updating.
997
     *
998
     * @return $this
999
     */
1000 1
    public function lockForUpdate()
1001
    {
1002 1
        $this->methods[] = new Method(__FUNCTION__);
1003
1004 1
        return $this;
1005
    }
1006
1007
    /**
1008
     * Share lock the selected rows in the table.
1009
     *
1010
     * @return $this
1011
     */
1012 1
    public function sharedLock()
1013
    {
1014 1
        $this->methods[] = new Method(__FUNCTION__);
1015
1016 1
        return $this;
1017
    }
1018
1019
    /**
1020
     * Apply the callback's query changes if the given "value" is true.
1021
     *
1022
     * @param  mixed  $value
1023
     * @param  callable  $callback
1024
     * @param  callable  $default
1025
     * @return $this
1026
     */
1027 1
    public function when($value, $callback, $default = null)
1028
    {
1029 1
        $this->methods[] = new Method(__FUNCTION__, [$value, $callback, $default]);
1030
1031 1
        return $this;
1032
    }
1033
1034
    /**
1035
     * Apply the callback's query changes if the given "value" is false.
1036
     *
1037
     * @param  mixed  $value
1038
     * @param  callable  $callback
1039
     * @param  callable  $default
1040
     * @return $this
1041
     */
1042 1
    public function unless($value, $callback, $default = null)
1043
    {
1044 1
        $this->methods[] = new Method(__FUNCTION__, [$value, $callback, $default]);
1045
1046 1
        return $this;
1047
    }
1048
1049
    /**
1050
     * Use the write pdo for query.
1051
     *
1052
     * @return $this
1053
     */
1054 2
    public function useWritePdo()
1055
    {
1056 2
        $this->methods[] = new Method(__FUNCTION__);
1057
1058 2
        return $this;
1059
    }
1060
}
1061