Complex classes like Builder 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 Builder, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class Builder |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * The base query builder instance. |
||
| 24 | * |
||
| 25 | * @var \Childish\connection\ConnectionInterface |
||
| 26 | */ |
||
| 27 | public $connection; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The database query grammar instance. |
||
| 31 | * |
||
| 32 | * @var \Childish\query\Grammar |
||
| 33 | */ |
||
| 34 | public $grammar; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The database query post processor instance. |
||
| 38 | * |
||
| 39 | * @var \Childish\query\Processor |
||
| 40 | */ |
||
| 41 | public $processor; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The current query value bindings. |
||
| 45 | * |
||
| 46 | * @var array |
||
| 47 | */ |
||
| 48 | public $bindings = [ |
||
| 49 | 'select' => [], |
||
| 50 | 'join' => [], |
||
| 51 | 'where' => [], |
||
| 52 | 'having' => [], |
||
| 53 | 'order' => [], |
||
| 54 | 'union' => [], |
||
| 55 | ]; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * An aggregate function and column to be run. |
||
| 59 | * |
||
| 60 | * @var array |
||
| 61 | */ |
||
| 62 | public $aggregate; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The columns that should be returned. |
||
| 66 | * |
||
| 67 | * @var array |
||
| 68 | */ |
||
| 69 | public $columns; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Indicates if the query returns distinct results. |
||
| 73 | * |
||
| 74 | * @var bool |
||
| 75 | */ |
||
| 76 | public $distinct = false; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * The table which the query is targeting. |
||
| 80 | * |
||
| 81 | * @var string |
||
| 82 | */ |
||
| 83 | public $from; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * The table joins for the query. |
||
| 87 | * |
||
| 88 | * @var array |
||
| 89 | */ |
||
| 90 | public $joins; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * The where constraints for the query. |
||
| 94 | * |
||
| 95 | * @var array |
||
| 96 | */ |
||
| 97 | public $wheres = []; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * The groupings for the query. |
||
| 101 | * |
||
| 102 | * @var array |
||
| 103 | */ |
||
| 104 | public $groups; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * The having constraints for the query. |
||
| 108 | * |
||
| 109 | * @var array |
||
| 110 | */ |
||
| 111 | public $havings; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * The orderings for the query. |
||
| 115 | * |
||
| 116 | * @var array |
||
| 117 | */ |
||
| 118 | public $orders; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * The maximum number of records to return. |
||
| 122 | * |
||
| 123 | * @var int |
||
| 124 | */ |
||
| 125 | public $limit; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * The number of records to skip. |
||
| 129 | * |
||
| 130 | * @var int |
||
| 131 | */ |
||
| 132 | public $offset; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * The query union statements. |
||
| 136 | * |
||
| 137 | * @var array |
||
| 138 | */ |
||
| 139 | public $unions; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * The maximum number of union records to return. |
||
| 143 | * |
||
| 144 | * @var int |
||
| 145 | */ |
||
| 146 | public $unionLimit; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * The number of union records to skip. |
||
| 150 | * |
||
| 151 | * @var int |
||
| 152 | */ |
||
| 153 | public $unionOffset; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * The orderings for the union query. |
||
| 157 | * |
||
| 158 | * @var array |
||
| 159 | */ |
||
| 160 | public $unionOrders; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Indicates whether row locking is being used. |
||
| 164 | * |
||
| 165 | * @var string|bool |
||
| 166 | */ |
||
| 167 | public $lock; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * All of the available clause operators. |
||
| 171 | * |
||
| 172 | * @var array |
||
| 173 | */ |
||
| 174 | public $operators = [ |
||
| 175 | '=', '<', '>', '<=', '>=', '<>', '!=', '<=>', |
||
| 176 | 'like', 'like binary', 'not like', 'between', 'ilike', |
||
| 177 | '&', '|', '^', '<<', '>>', |
||
| 178 | 'rlike', 'regexp', 'not regexp', |
||
| 179 | '~', '~*', '!~', '!~*', 'similar to', |
||
| 180 | 'not similar to', 'not ilike', '~~*', '!~~*', |
||
| 181 | ]; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Whether use write pdo for select. |
||
| 185 | * |
||
| 186 | * @var bool |
||
| 187 | */ |
||
| 188 | public $useWritePdo = false; |
||
| 189 | |||
| 190 | |||
| 191 | /** |
||
| 192 | * Builder constructor. |
||
| 193 | * |
||
| 194 | * @param \Childish\connection\ConnectionInterface $connection |
||
| 195 | * @param \Childish\query\Grammar|null $grammar |
||
| 196 | * @param \Childish\query\Processor|null $processor |
||
| 197 | */ |
||
| 198 | public function __construct( |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Set the columns to be selected. |
||
| 210 | * |
||
| 211 | * @param array|mixed $columns |
||
| 212 | * @return $this |
||
| 213 | */ |
||
| 214 | public function select($columns = ['*']) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Parse the sub-select query into SQL and bindings. |
||
| 223 | * |
||
| 224 | * @param mixed $query |
||
| 225 | * @return array |
||
| 226 | */ |
||
| 227 | protected function parseSubSelect($query) |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Add a new select column to the query. |
||
| 242 | * |
||
| 243 | * @param array|mixed $column |
||
| 244 | * @return $this |
||
| 245 | */ |
||
| 246 | public function addSelect($column) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Force the query to only return distinct results. |
||
| 257 | * |
||
| 258 | * @return $this |
||
| 259 | */ |
||
| 260 | public function distinct() |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Set the table which the query is targeting. |
||
| 269 | * |
||
| 270 | * @param string $table |
||
| 271 | * @return $this |
||
| 272 | */ |
||
| 273 | public function from($table) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Merge an array of where clauses and bindings. |
||
| 282 | * |
||
| 283 | * @param array $wheres |
||
| 284 | * @param array $bindings |
||
| 285 | * @return void |
||
| 286 | */ |
||
| 287 | public function mergeWheres($wheres, $bindings) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Add a basic where clause to the query. |
||
| 298 | * |
||
| 299 | * @param string|array|\Closure $column |
||
| 300 | * @param string|null $operator |
||
| 301 | * @param mixed $value |
||
| 302 | * @param string $boolean |
||
| 303 | * @return $this |
||
| 304 | */ |
||
| 305 | public function where($column, $operator = null, $value = null, $boolean = 'and') |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Add an array of where clauses to the query. |
||
| 364 | * |
||
| 365 | * @param array $column |
||
| 366 | * @param string $boolean |
||
| 367 | * @param string $method |
||
| 368 | * @return $this |
||
| 369 | */ |
||
| 370 | protected function addArrayOfWheres($column, $boolean, $method = 'where') |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Prepare the value and operator for a where clause. |
||
| 385 | * |
||
| 386 | * @param string $value |
||
| 387 | * @param string $operator |
||
| 388 | * @param bool $useDefault |
||
| 389 | * @return array |
||
| 390 | * @throws \InvalidArgumentException |
||
| 391 | */ |
||
| 392 | protected function prepareValueAndOperator($value, $operator, $useDefault = false) |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Determine if the given operator and value combination is legal. |
||
| 405 | * Prevents using Null values with invalid operators. |
||
| 406 | * |
||
| 407 | * @param string $operator |
||
| 408 | * @param mixed $value |
||
| 409 | * @return bool |
||
| 410 | */ |
||
| 411 | protected function invalidOperatorAndValue($operator, $value) |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Determine if the given operator is supported. |
||
| 419 | * |
||
| 420 | * @param string $operator |
||
| 421 | * @return bool |
||
| 422 | */ |
||
| 423 | protected function invalidOperator($operator) |
||
| 428 | |||
| 429 | /** |
||
| 430 | * Add an "or where" clause to the query. |
||
| 431 | * |
||
| 432 | * @param string|array|\Closure $column |
||
| 433 | * @param string|null $operator |
||
| 434 | * @param mixed $value |
||
| 435 | * @return \Childish\query\Builder|static |
||
| 436 | */ |
||
| 437 | public function orWhere($column, $operator = null, $value = null) |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Add a "where" clause comparing two columns to the query. |
||
| 444 | * |
||
| 445 | * @param string|array $first |
||
| 446 | * @param string|null $operator |
||
| 447 | * @param string|null $second |
||
| 448 | * @param string|null $boolean |
||
| 449 | * @return \Childish\query\Builder|static |
||
| 450 | */ |
||
| 451 | public function whereColumn($first, $operator = null, $second = null, $boolean = 'and') |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Add an "or where" clause comparing two columns to the query. |
||
| 481 | * |
||
| 482 | * @param string|array $first |
||
| 483 | * @param string|null $operator |
||
| 484 | * @param string|null $second |
||
| 485 | * @return \Childish\query\Builder|static |
||
| 486 | */ |
||
| 487 | public function orWhereColumn($first, $operator = null, $second = null) |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Add a raw where clause to the query. |
||
| 494 | * |
||
| 495 | * @param string $sql |
||
| 496 | * @param mixed $bindings |
||
| 497 | * @param string $boolean |
||
| 498 | * @return $this |
||
| 499 | */ |
||
| 500 | public function whereRaw($sql, $bindings = [], $boolean = 'and') |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Add a raw or where clause to the query. |
||
| 511 | * |
||
| 512 | * @param string $sql |
||
| 513 | * @param mixed $bindings |
||
| 514 | * @return \Childish\query\Builder|static |
||
| 515 | */ |
||
| 516 | public function orWhereRaw($sql, $bindings = []) |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Add a "where in" clause to the query. |
||
| 523 | * |
||
| 524 | * @param string $column |
||
| 525 | * @param mixed $values |
||
| 526 | * @param string $boolean |
||
| 527 | * @param bool $not |
||
| 528 | * @return $this |
||
| 529 | */ |
||
| 530 | public function whereIn($column, $values, $boolean = 'and', $not = false) |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Add an "or where in" clause to the query. |
||
| 563 | * |
||
| 564 | * @param string $column |
||
| 565 | * @param mixed $values |
||
| 566 | * @return \Childish\query\Builder|static |
||
| 567 | */ |
||
| 568 | public function orWhereIn($column, $values) |
||
| 572 | |||
| 573 | /** |
||
| 574 | * Add a "where not in" clause to the query. |
||
| 575 | * |
||
| 576 | * @param string $column |
||
| 577 | * @param mixed $values |
||
| 578 | * @param string $boolean |
||
| 579 | * @return \Childish\query\Builder|static |
||
| 580 | */ |
||
| 581 | public function whereNotIn($column, $values, $boolean = 'and') |
||
| 585 | |||
| 586 | /** |
||
| 587 | * Add an "or where not in" clause to the query. |
||
| 588 | * |
||
| 589 | * @param string $column |
||
| 590 | * @param mixed $values |
||
| 591 | * @return \Childish\query\Builder|static |
||
| 592 | */ |
||
| 593 | public function orWhereNotIn($column, $values) |
||
| 597 | |||
| 598 | |||
| 599 | /** |
||
| 600 | * Add an external sub-select to the query. |
||
| 601 | * |
||
| 602 | * @param string $column |
||
| 603 | * @param \Childish\query\Builder|static $query |
||
| 604 | * @param string $boolean |
||
| 605 | * @param bool $not |
||
| 606 | * @return $this |
||
| 607 | */ |
||
| 608 | protected function whereInExistingQuery($column, $query, $boolean, $not) |
||
| 618 | |||
| 619 | /** |
||
| 620 | * Add a "where null" clause to the query. |
||
| 621 | * |
||
| 622 | * @param string $column |
||
| 623 | * @param string $boolean |
||
| 624 | * @param bool $not |
||
| 625 | * @return $this |
||
| 626 | */ |
||
| 627 | public function whereNull($column, $boolean = 'and', $not = false) |
||
| 635 | |||
| 636 | /** |
||
| 637 | * Add an "or where null" clause to the query. |
||
| 638 | * |
||
| 639 | * @param string $column |
||
| 640 | * @return \Childish\query\Builder|static |
||
| 641 | */ |
||
| 642 | public function orWhereNull($column) |
||
| 646 | |||
| 647 | /** |
||
| 648 | * Add a "where not null" clause to the query. |
||
| 649 | * |
||
| 650 | * @param string $column |
||
| 651 | * @param string $boolean |
||
| 652 | * @return \Childish\query\Builder|static |
||
| 653 | */ |
||
| 654 | public function whereNotNull($column, $boolean = 'and') |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Add a where between statement to the query. |
||
| 661 | * |
||
| 662 | * @param string $column |
||
| 663 | * @param array $values |
||
| 664 | * @param string $boolean |
||
| 665 | * @param bool $not |
||
| 666 | * @return $this |
||
| 667 | */ |
||
| 668 | public function whereBetween($column, array $values, $boolean = 'and', $not = false) |
||
| 678 | |||
| 679 | /** |
||
| 680 | * Add an or where between statement to the query. |
||
| 681 | * |
||
| 682 | * @param string $column |
||
| 683 | * @param array $values |
||
| 684 | * @return \Childish\query\Builder|static |
||
| 685 | */ |
||
| 686 | public function orWhereBetween($column, array $values) |
||
| 690 | |||
| 691 | /** |
||
| 692 | * Add a where not between statement to the query. |
||
| 693 | * |
||
| 694 | * @param string $column |
||
| 695 | * @param array $values |
||
| 696 | * @param string $boolean |
||
| 697 | * @return \Childish\query\Builder|static |
||
| 698 | */ |
||
| 699 | public function whereNotBetween($column, array $values, $boolean = 'and') |
||
| 703 | |||
| 704 | /** |
||
| 705 | * Add an or where not between statement to the query. |
||
| 706 | * |
||
| 707 | * @param string $column |
||
| 708 | * @param array $values |
||
| 709 | * @return \Childish\query\Builder|static |
||
| 710 | */ |
||
| 711 | public function orWhereNotBetween($column, array $values) |
||
| 715 | |||
| 716 | /** |
||
| 717 | * Add an "or where not null" clause to the query. |
||
| 718 | * |
||
| 719 | * @param string $column |
||
| 720 | * @return \Childish\query\Builder|static |
||
| 721 | */ |
||
| 722 | public function orWhereNotNull($column) |
||
| 726 | |||
| 727 | /** |
||
| 728 | * Add a "where date" statement to the query. |
||
| 729 | * |
||
| 730 | * @param string $column |
||
| 731 | * @param string $operator |
||
| 732 | * @param mixed $value |
||
| 733 | * @param string $boolean |
||
| 734 | * @return \Childish\query\Builder|static |
||
| 735 | */ |
||
| 736 | public function whereDate($column, $operator, $value = null, $boolean = 'and') |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Add an "or where date" statement to the query. |
||
| 747 | * |
||
| 748 | * @param string $column |
||
| 749 | * @param string $operator |
||
| 750 | * @param string $value |
||
| 751 | * @return \Childish\query\Builder|static |
||
| 752 | */ |
||
| 753 | public function orWhereDate($column, $operator, $value) |
||
| 757 | |||
| 758 | /** |
||
| 759 | * Add a "where time" statement to the query. |
||
| 760 | * |
||
| 761 | * @param string $column |
||
| 762 | * @param string $operator |
||
| 763 | * @param int $value |
||
| 764 | * @param string $boolean |
||
| 765 | * @return \Childish\query\Builder|static |
||
| 766 | */ |
||
| 767 | public function whereTime($column, $operator, $value, $boolean = 'and') |
||
| 771 | |||
| 772 | /** |
||
| 773 | * Add an "or where time" statement to the query. |
||
| 774 | * |
||
| 775 | * @param string $column |
||
| 776 | * @param string $operator |
||
| 777 | * @param int $value |
||
| 778 | * @return \Childish\query\Builder|static |
||
| 779 | */ |
||
| 780 | public function orWhereTime($column, $operator, $value) |
||
| 784 | |||
| 785 | /** |
||
| 786 | * Add a "where day" statement to the query. |
||
| 787 | * |
||
| 788 | * @param string $column |
||
| 789 | * @param string $operator |
||
| 790 | * @param mixed $value |
||
| 791 | * @param string $boolean |
||
| 792 | * @return \Childish\query\Builder|static |
||
| 793 | */ |
||
| 794 | public function whereDay($column, $operator, $value = null, $boolean = 'and') |
||
| 802 | |||
| 803 | /** |
||
| 804 | * Add a "where month" statement to the query. |
||
| 805 | * |
||
| 806 | * @param string $column |
||
| 807 | * @param string $operator |
||
| 808 | * @param mixed $value |
||
| 809 | * @param string $boolean |
||
| 810 | * @return \Childish\query\Builder|static |
||
| 811 | */ |
||
| 812 | public function whereMonth($column, $operator, $value = null, $boolean = 'and') |
||
| 820 | |||
| 821 | /** |
||
| 822 | * Add a "where year" statement to the query. |
||
| 823 | * |
||
| 824 | * @param string $column |
||
| 825 | * @param string $operator |
||
| 826 | * @param mixed $value |
||
| 827 | * @param string $boolean |
||
| 828 | * @return \Childish\query\Builder|static |
||
| 829 | */ |
||
| 830 | public function whereYear($column, $operator, $value = null, $boolean = 'and') |
||
| 838 | |||
| 839 | /** |
||
| 840 | * Add a date based (year, month, day, time) statement to the query. |
||
| 841 | * |
||
| 842 | * @param string $type |
||
| 843 | * @param string $column |
||
| 844 | * @param string $operator |
||
| 845 | * @param int $value |
||
| 846 | * @param string $boolean |
||
| 847 | * @return $this |
||
| 848 | */ |
||
| 849 | protected function addDateBasedWhere($type, $column, $operator, $value, $boolean = 'and') |
||
| 857 | |||
| 858 | /** |
||
| 859 | * Add a nested where statement to the query. |
||
| 860 | * |
||
| 861 | * @param \Closure $callback |
||
| 862 | * @param string $boolean |
||
| 863 | * @return \Childish\query\Builder|static |
||
| 864 | */ |
||
| 865 | public function whereNested(Closure $callback, $boolean = 'and') |
||
| 871 | |||
| 872 | /** |
||
| 873 | * Create a new query instance for nested where condition. |
||
| 874 | * |
||
| 875 | * @return \Childish\query\Builder |
||
| 876 | */ |
||
| 877 | public function forNestedWhere() |
||
| 881 | |||
| 882 | /** |
||
| 883 | * Add another query builder as a nested where to the query builder. |
||
| 884 | * |
||
| 885 | * @param \Childish\query\Builder|static $query |
||
| 886 | * @param string $boolean |
||
| 887 | * @return $this |
||
| 888 | */ |
||
| 889 | public function addNestedWhereQuery($query, $boolean = 'and') |
||
| 901 | |||
| 902 | /** |
||
| 903 | * Add an exists clause to the query. |
||
| 904 | * |
||
| 905 | * @param \Closure $callback |
||
| 906 | * @param string $boolean |
||
| 907 | * @param bool $not |
||
| 908 | * @return $this |
||
| 909 | */ |
||
| 910 | public function whereExists(Closure $callback, $boolean = 'and', $not = false) |
||
| 921 | |||
| 922 | /** |
||
| 923 | * Add an or exists clause to the query. |
||
| 924 | * |
||
| 925 | * @param \Closure $callback |
||
| 926 | * @param bool $not |
||
| 927 | * @return \Childish\query\Builder|static |
||
| 928 | */ |
||
| 929 | public function orWhereExists(Closure $callback, $not = false) |
||
| 933 | |||
| 934 | /** |
||
| 935 | * Add a where not exists clause to the query. |
||
| 936 | * |
||
| 937 | * @param \Closure $callback |
||
| 938 | * @param string $boolean |
||
| 939 | * @return \Childish\query\Builder|static |
||
| 940 | */ |
||
| 941 | public function whereNotExists(Closure $callback, $boolean = 'and') |
||
| 945 | |||
| 946 | /** |
||
| 947 | * Add a where not exists clause to the query. |
||
| 948 | * |
||
| 949 | * @param \Closure $callback |
||
| 950 | * @return \Childish\query\Builder|static |
||
| 951 | */ |
||
| 952 | public function orWhereNotExists(Closure $callback) |
||
| 956 | |||
| 957 | /** |
||
| 958 | * Add an exists clause to the query. |
||
| 959 | * |
||
| 960 | * @param \Childish\query\Builder $query |
||
| 961 | * @param string $boolean |
||
| 962 | * @param bool $not |
||
| 963 | * @return $this |
||
| 964 | */ |
||
| 965 | public function addWhereExistsQuery(Builder $query, $boolean = 'and', $not = false) |
||
| 975 | |||
| 976 | |||
| 977 | /** |
||
| 978 | * Add a "group by" clause to the query. |
||
| 979 | * |
||
| 980 | * @param array ...$groups |
||
| 981 | * @return $this |
||
| 982 | */ |
||
| 983 | public function groupBy(...$groups) |
||
| 994 | |||
| 995 | /** |
||
| 996 | * Add a "having" clause to the query. |
||
| 997 | * |
||
| 998 | * @param string $column |
||
| 999 | * @param string|null $operator |
||
| 1000 | * @param string|null $value |
||
| 1001 | * @param string $boolean |
||
| 1002 | * @return $this |
||
| 1003 | */ |
||
| 1004 | public function having($column, $operator = null, $value = null, $boolean = 'and') |
||
| 1030 | |||
| 1031 | /** |
||
| 1032 | * Add a "or having" clause to the query. |
||
| 1033 | * |
||
| 1034 | * @param string $column |
||
| 1035 | * @param string|null $operator |
||
| 1036 | * @param string|null $value |
||
| 1037 | * @return \Childish\query\Builder|static |
||
| 1038 | */ |
||
| 1039 | public function orHaving($column, $operator = null, $value = null) |
||
| 1043 | |||
| 1044 | /** |
||
| 1045 | * Add a raw having clause to the query. |
||
| 1046 | * |
||
| 1047 | * @param string $sql |
||
| 1048 | * @param array $bindings |
||
| 1049 | * @param string $boolean |
||
| 1050 | * @return $this |
||
| 1051 | */ |
||
| 1052 | public function havingRaw($sql, array $bindings = [], $boolean = 'and') |
||
| 1062 | |||
| 1063 | /** |
||
| 1064 | * Add a raw or having clause to the query. |
||
| 1065 | * |
||
| 1066 | * @param string $sql |
||
| 1067 | * @param array $bindings |
||
| 1068 | * @return \Childish\query\Builder|static |
||
| 1069 | */ |
||
| 1070 | public function orHavingRaw($sql, array $bindings = []) |
||
| 1074 | |||
| 1075 | /** |
||
| 1076 | * Add an "order by" clause to the query. |
||
| 1077 | * |
||
| 1078 | * @param string $column |
||
| 1079 | * @param string $direction |
||
| 1080 | * @return $this |
||
| 1081 | */ |
||
| 1082 | public function orderBy($column, $direction = 'asc') |
||
| 1091 | |||
| 1092 | /** |
||
| 1093 | * Add a descending "order by" clause to the query. |
||
| 1094 | * |
||
| 1095 | * @param string $column |
||
| 1096 | * @return $this |
||
| 1097 | */ |
||
| 1098 | public function orderByDesc($column) |
||
| 1102 | |||
| 1103 | /** |
||
| 1104 | * Add a raw "order by" clause to the query. |
||
| 1105 | * |
||
| 1106 | * @param string $sql |
||
| 1107 | * @param array $bindings |
||
| 1108 | * @return $this |
||
| 1109 | */ |
||
| 1110 | public function orderByRaw($sql, $bindings = []) |
||
| 1120 | |||
| 1121 | /** |
||
| 1122 | * Alias to set the "offset" value of the query. |
||
| 1123 | * |
||
| 1124 | * @param int $value |
||
| 1125 | * @return \Childish\query\Builder|static |
||
| 1126 | */ |
||
| 1127 | public function skip($value) |
||
| 1131 | |||
| 1132 | /** |
||
| 1133 | * Set the "offset" value of the query. |
||
| 1134 | * |
||
| 1135 | * @param int $value |
||
| 1136 | * @return $this |
||
| 1137 | */ |
||
| 1138 | public function offset($value) |
||
| 1146 | |||
| 1147 | /** |
||
| 1148 | * Alias to set the "limit" value of the query. |
||
| 1149 | * |
||
| 1150 | * @param int $value |
||
| 1151 | * @return \Childish\query\Builder|static |
||
| 1152 | */ |
||
| 1153 | public function take($value) |
||
| 1157 | |||
| 1158 | /** |
||
| 1159 | * Set the "limit" value of the query. |
||
| 1160 | * |
||
| 1161 | * @param int $value |
||
| 1162 | * @return $this |
||
| 1163 | */ |
||
| 1164 | public function limit($value) |
||
| 1174 | |||
| 1175 | /** |
||
| 1176 | * Set the limit and offset for a given page. |
||
| 1177 | * |
||
| 1178 | * @param int $page |
||
| 1179 | * @param int $perPage |
||
| 1180 | * @return \Childish\query\Builder|static |
||
| 1181 | */ |
||
| 1182 | public function forPage($page, $perPage = 15) |
||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * Add a union statement to the query. |
||
| 1189 | * |
||
| 1190 | * @param \Childish\query\Builder|\Closure $query |
||
| 1191 | * @param bool $all |
||
| 1192 | * @return \Childish\query\Builder|static |
||
| 1193 | */ |
||
| 1194 | public function union($query, $all = false) |
||
| 1206 | |||
| 1207 | /** |
||
| 1208 | * Add a union all statement to the query. |
||
| 1209 | * |
||
| 1210 | * @param \Childish\query\Builder|\Closure $query |
||
| 1211 | * @return \Childish\query\Builder|static |
||
| 1212 | */ |
||
| 1213 | public function unionAll($query) |
||
| 1217 | |||
| 1218 | /** |
||
| 1219 | * Lock the selected rows in the table. |
||
| 1220 | * |
||
| 1221 | * @param string|bool $value |
||
| 1222 | * @return $this |
||
| 1223 | */ |
||
| 1224 | public function lock($value = true) |
||
| 1234 | |||
| 1235 | /** |
||
| 1236 | * Lock the selected rows in the table for updating. |
||
| 1237 | * |
||
| 1238 | * @return \Childish\query\Builder |
||
| 1239 | */ |
||
| 1240 | public function lockForUpdate() |
||
| 1244 | |||
| 1245 | /** |
||
| 1246 | * Share lock the selected rows in the table. |
||
| 1247 | * |
||
| 1248 | * @return \Childish\query\Builder |
||
| 1249 | */ |
||
| 1250 | public function sharedLock() |
||
| 1254 | |||
| 1255 | /** |
||
| 1256 | * Get the SQL representation of the query. |
||
| 1257 | * |
||
| 1258 | * @return string |
||
| 1259 | */ |
||
| 1260 | public function toSql() |
||
| 1264 | |||
| 1265 | /** |
||
| 1266 | * Execute a query for a single record by ID. |
||
| 1267 | * |
||
| 1268 | * @param int $id |
||
| 1269 | * @param array $columns |
||
| 1270 | * @return mixed|static |
||
| 1271 | */ |
||
| 1272 | public function find($id, $columns = ['*']) |
||
| 1276 | |||
| 1277 | /** |
||
| 1278 | * Get a single column's value from the first result of a query. |
||
| 1279 | * |
||
| 1280 | * @param string $column |
||
| 1281 | * @return mixed |
||
| 1282 | */ |
||
| 1283 | public function value($column) |
||
| 1289 | |||
| 1290 | /** |
||
| 1291 | * Execute the query as a "select" statement. |
||
| 1292 | * |
||
| 1293 | * @param array $columns |
||
| 1294 | * @return \childish\support\Collection |
||
| 1295 | */ |
||
| 1296 | public function get($columns = ['*']) |
||
| 1310 | |||
| 1311 | /** |
||
| 1312 | * Run the query as a "select" statement against the connection. |
||
| 1313 | * |
||
| 1314 | * @return array |
||
| 1315 | */ |
||
| 1316 | protected function runSelect() |
||
| 1322 | |||
| 1323 | |||
| 1324 | /** |
||
| 1325 | * Remove the column aliases since they will break count queries. |
||
| 1326 | * |
||
| 1327 | * @param array $columns |
||
| 1328 | * @return array |
||
| 1329 | */ |
||
| 1330 | protected function withoutSelectAliases(array $columns) |
||
| 1337 | |||
| 1338 | /** |
||
| 1339 | * Get a generator for the given query. |
||
| 1340 | * |
||
| 1341 | * @return \Generator |
||
| 1342 | */ |
||
| 1343 | public function cursor() |
||
| 1353 | |||
| 1354 | /** |
||
| 1355 | * Chunk the results of a query by comparing numeric IDs. |
||
| 1356 | * |
||
| 1357 | * @param int $count |
||
| 1358 | * @param callable $callback |
||
| 1359 | * @param string $column |
||
| 1360 | * @param string $alias |
||
| 1361 | * @return bool |
||
| 1362 | */ |
||
| 1363 | public function chunkById($count, callable $callback, $column = 'id', $alias = null) |
||
| 1397 | |||
| 1398 | /** |
||
| 1399 | * Throw an exception if the query doesn't have an orderBy clause. |
||
| 1400 | * |
||
| 1401 | * @return void |
||
| 1402 | * @throws \RuntimeException |
||
| 1403 | */ |
||
| 1404 | protected function enforceOrderBy() |
||
| 1410 | |||
| 1411 | /** |
||
| 1412 | * Get an array with the values of a given column. |
||
| 1413 | * |
||
| 1414 | * @param string $column |
||
| 1415 | * @param string|null $key |
||
| 1416 | * @return \Childish\support\Collection |
||
| 1417 | */ |
||
| 1418 | public function pluck($column, $key = null) |
||
| 1430 | |||
| 1431 | /** |
||
| 1432 | * Strip off the table name or alias from a column identifier. |
||
| 1433 | * |
||
| 1434 | * @param string $column |
||
| 1435 | * @return string|null |
||
| 1436 | */ |
||
| 1437 | protected function stripTableForPluck($column) |
||
| 1441 | |||
| 1442 | /** |
||
| 1443 | * Concatenate values of a given column as a string. |
||
| 1444 | * |
||
| 1445 | * @param string $column |
||
| 1446 | * @param string $glue |
||
| 1447 | * @return string |
||
| 1448 | */ |
||
| 1449 | public function implode($column, $glue = '') |
||
| 1453 | |||
| 1454 | /** |
||
| 1455 | * Determine if any rows exist for the current query. |
||
| 1456 | * |
||
| 1457 | * @return bool |
||
| 1458 | */ |
||
| 1459 | public function exists() |
||
| 1476 | |||
| 1477 | /** |
||
| 1478 | * Retrieve the "count" result of the query. |
||
| 1479 | * |
||
| 1480 | * @param string $columns |
||
| 1481 | * @return int |
||
| 1482 | */ |
||
| 1483 | public function count($columns = '*') |
||
| 1487 | |||
| 1488 | /** |
||
| 1489 | * Retrieve the minimum value of a given column. |
||
| 1490 | * |
||
| 1491 | * @param string $column |
||
| 1492 | * @return mixed |
||
| 1493 | */ |
||
| 1494 | public function min($column) |
||
| 1498 | |||
| 1499 | /** |
||
| 1500 | * Retrieve the maximum value of a given column. |
||
| 1501 | * |
||
| 1502 | * @param string $column |
||
| 1503 | * @return mixed |
||
| 1504 | */ |
||
| 1505 | public function max($column) |
||
| 1509 | |||
| 1510 | /** |
||
| 1511 | * Retrieve the sum of the values of a given column. |
||
| 1512 | * |
||
| 1513 | * @param string $column |
||
| 1514 | * @return mixed |
||
| 1515 | */ |
||
| 1516 | public function sum($column) |
||
| 1522 | |||
| 1523 | /** |
||
| 1524 | * Retrieve the average of the values of a given column. |
||
| 1525 | * |
||
| 1526 | * @param string $column |
||
| 1527 | * @return mixed |
||
| 1528 | */ |
||
| 1529 | public function avg($column) |
||
| 1533 | |||
| 1534 | /** |
||
| 1535 | * Alias for the "avg" method. |
||
| 1536 | * |
||
| 1537 | * @param string $column |
||
| 1538 | * @return mixed |
||
| 1539 | */ |
||
| 1540 | public function average($column) |
||
| 1544 | |||
| 1545 | /** |
||
| 1546 | * Execute an aggregate function on the database. |
||
| 1547 | * |
||
| 1548 | * @param string $function |
||
| 1549 | * @param array $columns |
||
| 1550 | * @return mixed |
||
| 1551 | */ |
||
| 1552 | public function aggregate($function, $columns = ['*']) |
||
| 1563 | |||
| 1564 | /** |
||
| 1565 | * Clone the query without the given properties. |
||
| 1566 | * |
||
| 1567 | * @param array $properties |
||
| 1568 | * @return static |
||
| 1569 | */ |
||
| 1570 | public function cloneWithout(array $properties) |
||
| 1578 | |||
| 1579 | /** |
||
| 1580 | * Clone the query without the given bindings. |
||
| 1581 | * |
||
| 1582 | * @param array $except |
||
| 1583 | * @return static |
||
| 1584 | */ |
||
| 1585 | public function cloneWithoutBindings(array $except) |
||
| 1593 | |||
| 1594 | /** |
||
| 1595 | * Call the given Closure with the given value then return the value. |
||
| 1596 | * |
||
| 1597 | * @param mixed $value |
||
| 1598 | * @param callable|null $callback |
||
| 1599 | * @return mixed |
||
| 1600 | */ |
||
| 1601 | public function higherOrderTap($value, $callback = null) |
||
| 1608 | |||
| 1609 | /** |
||
| 1610 | * Execute a numeric aggregate function on the database. |
||
| 1611 | * |
||
| 1612 | * @param string $function |
||
| 1613 | * @param array $columns |
||
| 1614 | * @return float|int |
||
| 1615 | */ |
||
| 1616 | public function numericAggregate($function, $columns = ['*']) |
||
| 1637 | |||
| 1638 | /** |
||
| 1639 | * Set the aggregate property without running the query. |
||
| 1640 | * |
||
| 1641 | * @param string $function |
||
| 1642 | * @param array $columns |
||
| 1643 | * @return $this |
||
| 1644 | */ |
||
| 1645 | protected function setAggregate($function, $columns) |
||
| 1657 | |||
| 1658 | /** |
||
| 1659 | * Insert a new record into the database. |
||
| 1660 | * |
||
| 1661 | * @param array $values |
||
| 1662 | * @return bool |
||
| 1663 | */ |
||
| 1664 | public function insert(array $values) |
||
| 1696 | |||
| 1697 | /** |
||
| 1698 | * Insert a new record and get the value of the primary key. |
||
| 1699 | * |
||
| 1700 | * @param array $values |
||
| 1701 | * @param string|null $sequence |
||
| 1702 | * @return int |
||
| 1703 | */ |
||
| 1704 | public function insertGetId(array $values, $sequence = null) |
||
| 1712 | |||
| 1713 | /** |
||
| 1714 | * Update a record in the database. |
||
| 1715 | * |
||
| 1716 | * @param array $values |
||
| 1717 | * @return int |
||
| 1718 | */ |
||
| 1719 | public function update(array $values) |
||
| 1726 | |||
| 1727 | /** |
||
| 1728 | * Insert or update a record matching the attributes, and fill it with values. |
||
| 1729 | * |
||
| 1730 | * @param array $attributes |
||
| 1731 | * @param array $values |
||
| 1732 | * @return bool |
||
| 1733 | */ |
||
| 1734 | public function updateOrInsert(array $attributes, array $values = []) |
||
| 1742 | |||
| 1743 | /** |
||
| 1744 | * Increment a column's value by a given amount. |
||
| 1745 | * |
||
| 1746 | * @param string $column |
||
| 1747 | * @param int $amount |
||
| 1748 | * @param array $extra |
||
| 1749 | * @return int |
||
| 1750 | */ |
||
| 1751 | public function increment($column, $amount = 1, array $extra = []) |
||
| 1763 | |||
| 1764 | /** |
||
| 1765 | * Decrement a column's value by a given amount. |
||
| 1766 | * |
||
| 1767 | * @param string $column |
||
| 1768 | * @param int $amount |
||
| 1769 | * @param array $extra |
||
| 1770 | * @return int |
||
| 1771 | */ |
||
| 1772 | public function decrement($column, $amount = 1, array $extra = []) |
||
| 1784 | |||
| 1785 | /** |
||
| 1786 | * Delete a record from the database. |
||
| 1787 | * |
||
| 1788 | * @param mixed $id |
||
| 1789 | * @return int |
||
| 1790 | */ |
||
| 1791 | public function delete($id = null) |
||
| 1804 | |||
| 1805 | /** |
||
| 1806 | * Run a truncate statement on the table. |
||
| 1807 | * |
||
| 1808 | * @return void |
||
| 1809 | */ |
||
| 1810 | public function truncate() |
||
| 1816 | |||
| 1817 | /** |
||
| 1818 | * Get a new instance of the query builder. |
||
| 1819 | * |
||
| 1820 | * @return \Childish\query\Builder |
||
| 1821 | */ |
||
| 1822 | public function newQuery() |
||
| 1826 | |||
| 1827 | /** |
||
| 1828 | * Create a new query instance for a sub-query. |
||
| 1829 | * |
||
| 1830 | * @return \Childish\query\Builder |
||
| 1831 | */ |
||
| 1832 | protected function forSubQuery() |
||
| 1836 | |||
| 1837 | /** |
||
| 1838 | * Create a raw database expression. |
||
| 1839 | * |
||
| 1840 | * @param $value |
||
| 1841 | * @return mixed |
||
| 1842 | */ |
||
| 1843 | public function raw($value) |
||
| 1847 | |||
| 1848 | /** |
||
| 1849 | * Get the current query value bindings in a flattened array. |
||
| 1850 | * |
||
| 1851 | * @return array |
||
| 1852 | */ |
||
| 1853 | public function getBindings() |
||
| 1857 | |||
| 1858 | /** |
||
| 1859 | * Get the raw array of bindings. |
||
| 1860 | * |
||
| 1861 | * @return array |
||
| 1862 | */ |
||
| 1863 | public function getRawBindings() |
||
| 1867 | |||
| 1868 | /** |
||
| 1869 | * Set the bindings on the query builder. |
||
| 1870 | * |
||
| 1871 | * @param array $bindings |
||
| 1872 | * @param string $type |
||
| 1873 | * @return $this |
||
| 1874 | * @throws \InvalidArgumentException |
||
| 1875 | */ |
||
| 1876 | public function setBindings(array $bindings, $type = 'where') |
||
| 1886 | |||
| 1887 | /** |
||
| 1888 | * Add a binding to the query. |
||
| 1889 | * |
||
| 1890 | * @param mixed $value |
||
| 1891 | * @param string $type |
||
| 1892 | * @return $this |
||
| 1893 | * @throws \InvalidArgumentException |
||
| 1894 | */ |
||
| 1895 | public function addBinding($value, $type = 'where') |
||
| 1909 | |||
| 1910 | /** |
||
| 1911 | * Merge an array of bindings into our bindings. |
||
| 1912 | * |
||
| 1913 | * @param \Childish\query\Builder $query |
||
| 1914 | * @return $this |
||
| 1915 | */ |
||
| 1916 | public function mergeBindings(Builder $query) |
||
| 1922 | |||
| 1923 | /** |
||
| 1924 | * Remove all of the expressions from a list of bindings. |
||
| 1925 | * |
||
| 1926 | * @param array $bindings |
||
| 1927 | * @return array |
||
| 1928 | */ |
||
| 1929 | protected function cleanBindings(array $bindings) |
||
| 1933 | |||
| 1934 | /** |
||
| 1935 | * Get the database connection instance. |
||
| 1936 | * |
||
| 1937 | * @return \Childish\connection\ConnectionInterface |
||
| 1938 | */ |
||
| 1939 | public function getConnection() |
||
| 1943 | |||
| 1944 | /** |
||
| 1945 | * Get the database query processor instance. |
||
| 1946 | * |
||
| 1947 | * @return \Childish\query\Processor |
||
| 1948 | */ |
||
| 1949 | public function getProcessor() |
||
| 1953 | |||
| 1954 | /** |
||
| 1955 | * Get the query grammar instance. |
||
| 1956 | * |
||
| 1957 | * @return \Childish\query\Grammar |
||
| 1958 | */ |
||
| 1959 | public function getGrammar() |
||
| 1963 | |||
| 1964 | /** |
||
| 1965 | * Use the write pdo for query. |
||
| 1966 | * |
||
| 1967 | * @return $this |
||
| 1968 | */ |
||
| 1969 | public function useWritePdo() |
||
| 1975 | |||
| 1976 | /** |
||
| 1977 | * Chunk the results of the query. |
||
| 1978 | * |
||
| 1979 | * @param int $count |
||
| 1980 | * @param callable $callback |
||
| 1981 | * @return bool |
||
| 1982 | */ |
||
| 1983 | public function chunk($count, callable $callback) |
||
| 2015 | |||
| 2016 | /** |
||
| 2017 | * Execute a callback over each item while chunking. |
||
| 2018 | * |
||
| 2019 | * @param callable $callback |
||
| 2020 | * @param int $count |
||
| 2021 | * @return bool |
||
| 2022 | */ |
||
| 2023 | public function each(callable $callback, $count = 1000) |
||
| 2033 | |||
| 2034 | /** |
||
| 2035 | * Execute the query and get the first result. |
||
| 2036 | * |
||
| 2037 | * @param array $columns |
||
| 2038 | * @return \childish\support\Collection |
||
| 2039 | */ |
||
| 2040 | public function first($columns = ['*']) |
||
| 2044 | |||
| 2045 | /** |
||
| 2046 | * Apply the callback's query changes if the given "value" is true. |
||
| 2047 | * |
||
| 2048 | * @param mixed $value |
||
| 2049 | * @param callable $callback |
||
| 2050 | * @param callable $default |
||
| 2051 | * @return mixed |
||
| 2052 | */ |
||
| 2053 | public function when($value, $callback, $default = null) |
||
| 2063 | |||
| 2064 | /** |
||
| 2065 | * Pass the query to a given callback. |
||
| 2066 | * |
||
| 2067 | * @param \Closure $callback |
||
| 2068 | * @return \Childish\query\Builder |
||
| 2069 | */ |
||
| 2070 | public function tap($callback) |
||
| 2074 | |||
| 2075 | /** |
||
| 2076 | * Apply the callback's query changes if the given "value" is false. |
||
| 2077 | * |
||
| 2078 | * @param mixed $value |
||
| 2079 | * @param callable $callback |
||
| 2080 | * @param callable $default |
||
| 2081 | * @return mixed |
||
| 2082 | */ |
||
| 2083 | public function unless($value, $callback, $default = null) |
||
| 2093 | } |
||
| 2094 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.