Complex classes like Select 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 Select, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class Select extends AbstractQuery implements SelectInterface, SubselectInterface |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * |
||
| 25 | * An array of union SELECT statements. |
||
| 26 | * |
||
| 27 | * @var array |
||
| 28 | * |
||
| 29 | */ |
||
| 30 | protected $union = array(); |
||
| 31 | |||
| 32 | /** |
||
| 33 | * |
||
| 34 | * Is this a SELECT FOR UPDATE? |
||
| 35 | * |
||
| 36 | * @var |
||
| 37 | * |
||
| 38 | */ |
||
| 39 | protected $for_update = false; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * |
||
| 43 | * The columns to be selected. |
||
| 44 | * |
||
| 45 | * @var array |
||
| 46 | * |
||
| 47 | */ |
||
| 48 | protected $cols = array(); |
||
| 49 | |||
| 50 | /** |
||
| 51 | * |
||
| 52 | * Select from these tables; includes JOIN clauses. |
||
| 53 | * |
||
| 54 | * @var array |
||
| 55 | * |
||
| 56 | */ |
||
| 57 | protected $from = array(); |
||
| 58 | |||
| 59 | /** |
||
| 60 | * |
||
| 61 | * The current key in the `$from` array. |
||
| 62 | * |
||
| 63 | * @var int |
||
| 64 | * |
||
| 65 | */ |
||
| 66 | protected $from_key = -1; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * |
||
| 70 | * Tracks which JOIN clauses are attached to which FROM tables. |
||
| 71 | * |
||
| 72 | * @var array |
||
| 73 | * |
||
| 74 | */ |
||
| 75 | protected $join = array(); |
||
| 76 | |||
| 77 | /** |
||
| 78 | * |
||
| 79 | * GROUP BY these columns. |
||
| 80 | * |
||
| 81 | * @var array |
||
| 82 | * |
||
| 83 | */ |
||
| 84 | protected $group_by = array(); |
||
| 85 | |||
| 86 | /** |
||
| 87 | * |
||
| 88 | * The list of HAVING conditions. |
||
| 89 | * |
||
| 90 | * @var array |
||
| 91 | * |
||
| 92 | */ |
||
| 93 | protected $having = array(); |
||
| 94 | |||
| 95 | /** |
||
| 96 | * |
||
| 97 | * The page number to select. |
||
| 98 | * |
||
| 99 | * @var int |
||
| 100 | * |
||
| 101 | */ |
||
| 102 | protected $page = 0; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * |
||
| 106 | * The number of rows per page. |
||
| 107 | * |
||
| 108 | * @var int |
||
| 109 | * |
||
| 110 | */ |
||
| 111 | protected $paging = 10; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * |
||
| 115 | * Tracks table references to avoid duplicate identifiers. |
||
| 116 | * |
||
| 117 | * @var array |
||
| 118 | * |
||
| 119 | */ |
||
| 120 | protected $table_refs = array(); |
||
| 121 | |||
| 122 | /** |
||
| 123 | * |
||
| 124 | * Returns this query object as an SQL statement string. |
||
| 125 | * |
||
| 126 | * @return string An SQL statement string. |
||
| 127 | * |
||
| 128 | */ |
||
| 129 | 159 | public function getStatement() |
|
| 130 | { |
||
| 131 | 159 | $union = ''; |
|
| 132 | 159 | if ($this->union) { |
|
|
|
|||
| 133 | $union = implode(PHP_EOL, $this->union) . PHP_EOL; |
||
| 134 | } |
||
| 135 | 5 | return $union . $this->build(); |
|
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * |
||
| 140 | * Sets the number of rows per page. |
||
| 141 | * |
||
| 142 | * @param int $paging The number of rows to page at. |
||
| 143 | * |
||
| 144 | * @return $this |
||
| 145 | * |
||
| 146 | */ |
||
| 147 | 10 | public function setPaging($paging) |
|
| 148 | { |
||
| 149 | 10 | $this->paging = (int) $paging; |
|
| 150 | 10 | if ($this->page) { |
|
| 151 | $this->setPagingLimitOffset(); |
||
| 152 | } |
||
| 153 | 10 | return $this; |
|
| 154 | } |
||
| 155 | |||
| 156 | /** |
||
| 157 | * |
||
| 158 | * Gets the number of rows per page. |
||
| 159 | * |
||
| 160 | * @return int The number of rows per page. |
||
| 161 | * |
||
| 162 | */ |
||
| 163 | 5 | public function getPaging() |
|
| 167 | |||
| 168 | /** |
||
| 169 | * |
||
| 170 | * Makes the select FOR UPDATE (or not). |
||
| 171 | * |
||
| 172 | * @param bool $enable Whether or not the SELECT is FOR UPDATE (default |
||
| 173 | * true). |
||
| 174 | * |
||
| 175 | * @return $this |
||
| 176 | * |
||
| 177 | */ |
||
| 178 | 20 | public function forUpdate($enable = true) |
|
| 179 | { |
||
| 180 | 20 | $this->for_update = (bool) $enable; |
|
| 181 | 20 | return $this; |
|
| 182 | 5 | } |
|
| 183 | |||
| 184 | /** |
||
| 185 | * |
||
| 186 | * Makes the select DISTINCT (or not). |
||
| 187 | * |
||
| 188 | * @param bool $enable Whether or not the SELECT is DISTINCT (default |
||
| 189 | * true). |
||
| 190 | * |
||
| 191 | * @return $this |
||
| 192 | * |
||
| 193 | */ |
||
| 194 | 11 | public function distinct($enable = true) |
|
| 195 | { |
||
| 196 | $this->setFlag('DISTINCT', $enable); |
||
| 197 | 6 | return $this; |
|
| 198 | 11 | } |
|
| 199 | |||
| 200 | /** |
||
| 201 | * |
||
| 202 | * Adds columns to the query. |
||
| 203 | * |
||
| 204 | * Multiple calls to cols() will append to the list of columns, not |
||
| 205 | * overwrite the previous columns. |
||
| 206 | * |
||
| 207 | * @param array $cols The column(s) to add to the query. The elements can be |
||
| 208 | * any mix of these: `array("col", "col AS alias", "col" => "alias")` |
||
| 209 | * |
||
| 210 | * @return $this |
||
| 211 | * |
||
| 212 | */ |
||
| 213 | 184 | public function cols(array $cols) |
|
| 220 | |||
| 221 | /** |
||
| 222 | * |
||
| 223 | * Adds a column and alias to the columns to be selected. |
||
| 224 | * |
||
| 225 | * @param mixed $key If an integer, ignored. Otherwise, the column to be |
||
| 226 | * added. |
||
| 227 | * |
||
| 228 | * @param mixed $val If $key was an integer, the column to be added; |
||
| 229 | * otherwise, the column alias. |
||
| 230 | * |
||
| 231 | * @return null |
||
| 232 | * |
||
| 233 | */ |
||
| 234 | 145 | protected function addCol($key, $val) |
|
| 243 | |||
| 244 | /** |
||
| 245 | * |
||
| 246 | * Adds a column with an alias to the columns to be selected. |
||
| 247 | * |
||
| 248 | * @param string $spec The column specification: "col alias", |
||
| 249 | * "col AS alias", or something else entirely. |
||
| 250 | * |
||
| 251 | */ |
||
| 252 | 145 | protected function addColWithAlias($spec) |
|
| 267 | |||
| 268 | /** |
||
| 269 | * |
||
| 270 | * Remove a column via its alias. |
||
| 271 | * |
||
| 272 | * @param string $alias The column to remove |
||
| 273 | * |
||
| 274 | * @return boolean |
||
| 275 | * |
||
| 276 | */ |
||
| 277 | 15 | public function removeCol($alias) |
|
| 293 | |||
| 294 | /** |
||
| 295 | * |
||
| 296 | * Does the query have any columns in it? |
||
| 297 | * |
||
| 298 | * @return bool |
||
| 299 | * |
||
| 300 | */ |
||
| 301 | public function hasCols() |
||
| 305 | |||
| 306 | /** |
||
| 307 | * |
||
| 308 | * Returns a list of columns. |
||
| 309 | * |
||
| 310 | * @return array |
||
| 311 | * |
||
| 312 | */ |
||
| 313 | 15 | public function getCols() |
|
| 317 | |||
| 318 | /** |
||
| 319 | * |
||
| 320 | * Tracks table references. |
||
| 321 | * |
||
| 322 | * @param string $type FROM, JOIN, etc. |
||
| 323 | * |
||
| 324 | * @param string $spec The table and alias name. |
||
| 325 | * |
||
| 326 | * @return null |
||
| 327 | * |
||
| 328 | * @throws Exception when the reference has already been used. |
||
| 329 | * |
||
| 330 | */ |
||
| 331 | 59 | protected function addTableRef($type, $spec) |
|
| 347 | |||
| 348 | /** |
||
| 349 | * |
||
| 350 | * Adds a FROM element to the query; quotes the table name automatically. |
||
| 351 | * |
||
| 352 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 353 | * |
||
| 354 | * @return $this |
||
| 355 | * |
||
| 356 | */ |
||
| 357 | public function from($spec) |
||
| 362 | |||
| 363 | /** |
||
| 364 | * |
||
| 365 | * Adds a raw unquoted FROM element to the query; useful for adding FROM |
||
| 366 | * elements that are functions. |
||
| 367 | * |
||
| 368 | * @param string $spec The table specification, e.g. "function_name()". |
||
| 369 | * |
||
| 370 | * @return $this |
||
| 371 | * |
||
| 372 | */ |
||
| 373 | public function fromRaw($spec) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * |
||
| 381 | * Adds to the $from property and increments the key count. |
||
| 382 | * |
||
| 383 | * @param string $spec The table specification. |
||
| 384 | * |
||
| 385 | * @return $this |
||
| 386 | * |
||
| 387 | */ |
||
| 388 | 89 | protected function addFrom($spec) |
|
| 394 | |||
| 395 | /** |
||
| 396 | * |
||
| 397 | * Adds an aliased sub-select to the query. |
||
| 398 | * |
||
| 399 | * @param string|Select $spec If a Select object, use as the sub-select; |
||
| 400 | * if a string, the sub-select string. |
||
| 401 | * |
||
| 402 | * @param string $name The alias name for the sub-select. |
||
| 403 | * |
||
| 404 | * @return $this |
||
| 405 | * |
||
| 406 | */ |
||
| 407 | 5 | public function fromSubSelect($spec, $name) |
|
| 414 | |||
| 415 | /** |
||
| 416 | * |
||
| 417 | * Formats a sub-SELECT statement, binding values from a Select object as |
||
| 418 | * needed. |
||
| 419 | * |
||
| 420 | * @param string|SelectInterface $spec A sub-SELECT specification. |
||
| 421 | * |
||
| 422 | * @param string $indent Indent each line with this string. |
||
| 423 | * |
||
| 424 | * @return string The sub-SELECT string. |
||
| 425 | * |
||
| 426 | */ |
||
| 427 | 15 | protected function subSelect($spec, $indent) |
|
| 437 | |||
| 438 | /** |
||
| 439 | * |
||
| 440 | * Adds a JOIN table and columns to the query. |
||
| 441 | * |
||
| 442 | * @param string $join The join type: inner, left, natural, etc. |
||
| 443 | * |
||
| 444 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 445 | * |
||
| 446 | * @param string $cond Join on this condition. |
||
| 447 | * |
||
| 448 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 449 | * |
||
| 450 | * @return $this |
||
| 451 | * |
||
| 452 | * @throws Exception |
||
| 453 | * |
||
| 454 | */ |
||
| 455 | 5 | public function join($join, $spec, $cond = null, array $bind = array()) |
|
| 464 | |||
| 465 | /** |
||
| 466 | * |
||
| 467 | * Fixes a JOIN condition to quote names in the condition and prefix it |
||
| 468 | * with a condition type ('ON' is the default and 'USING' is recognized). |
||
| 469 | * |
||
| 470 | * @param string $cond Join on this condition. |
||
| 471 | * |
||
| 472 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 473 | * |
||
| 474 | * @return string |
||
| 475 | * |
||
| 476 | */ |
||
| 477 | 25 | protected function fixJoinCondition($cond, array $bind) |
|
| 496 | |||
| 497 | /** |
||
| 498 | * |
||
| 499 | * Adds a INNER JOIN table and columns to the query. |
||
| 500 | * |
||
| 501 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 502 | * |
||
| 503 | * @param string $cond Join on this condition. |
||
| 504 | * |
||
| 505 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 506 | * |
||
| 507 | * @return $this |
||
| 508 | * |
||
| 509 | * @throws Exception |
||
| 510 | * |
||
| 511 | */ |
||
| 512 | 10 | public function innerJoin($spec, $cond = null, array $bind = array()) |
|
| 516 | |||
| 517 | /** |
||
| 518 | * |
||
| 519 | * Adds a LEFT JOIN table and columns to the query. |
||
| 520 | * |
||
| 521 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 522 | * |
||
| 523 | * @param string $cond Join on this condition. |
||
| 524 | * |
||
| 525 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 526 | * |
||
| 527 | * @return $this |
||
| 528 | * |
||
| 529 | * @throws Exception |
||
| 530 | * |
||
| 531 | */ |
||
| 532 | 10 | public function leftJoin($spec, $cond = null, array $bind = array()) |
|
| 536 | |||
| 537 | /** |
||
| 538 | * |
||
| 539 | * Adds a JOIN to an aliased subselect and columns to the query. |
||
| 540 | * |
||
| 541 | * @param string $join The join type: inner, left, natural, etc. |
||
| 542 | * |
||
| 543 | * @param string|Select $spec If a Select |
||
| 544 | * object, use as the sub-select; if a string, the sub-select |
||
| 545 | * command string. |
||
| 546 | * |
||
| 547 | * @param string $name The alias name for the sub-select. |
||
| 548 | * |
||
| 549 | * @param string $cond Join on this condition. |
||
| 550 | * |
||
| 551 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 552 | * |
||
| 553 | * @return $this |
||
| 554 | * |
||
| 555 | * @throws Exception |
||
| 556 | * |
||
| 557 | */ |
||
| 558 | 5 | public function joinSubSelect($join, $spec, $name, $cond = null, array $bind = array()) |
|
| 570 | |||
| 571 | /** |
||
| 572 | * |
||
| 573 | * Adds the JOIN to the right place, given whether or not a FROM has been |
||
| 574 | * specified yet. |
||
| 575 | * |
||
| 576 | * @param string $spec The JOIN clause. |
||
| 577 | * |
||
| 578 | * @return $this |
||
| 579 | * |
||
| 580 | */ |
||
| 581 | 10 | protected function addJoin($spec) |
|
| 587 | |||
| 588 | /** |
||
| 589 | * |
||
| 590 | * Adds grouping to the query. |
||
| 591 | * |
||
| 592 | * @param array $spec The column(s) to group by. |
||
| 593 | * |
||
| 594 | * @return $this |
||
| 595 | * |
||
| 596 | */ |
||
| 597 | 5 | public function groupBy(array $spec) |
|
| 604 | |||
| 605 | /** |
||
| 606 | * |
||
| 607 | * Adds a HAVING condition to the query by AND. If the condition has |
||
| 608 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 609 | * those placeholders sequentially. |
||
| 610 | * |
||
| 611 | * @param string $cond The HAVING condition. |
||
| 612 | * |
||
| 613 | * @return $this |
||
| 614 | * |
||
| 615 | */ |
||
| 616 | 5 | public function having($cond) |
|
| 621 | |||
| 622 | /** |
||
| 623 | * |
||
| 624 | * Adds a HAVING condition to the query by AND. If the condition has |
||
| 625 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 626 | * those placeholders sequentially. |
||
| 627 | * |
||
| 628 | * @param string $cond The HAVING condition. |
||
| 629 | * |
||
| 630 | * @return $this |
||
| 631 | * |
||
| 632 | * @see having() |
||
| 633 | * |
||
| 634 | */ |
||
| 635 | public function orHaving($cond) |
||
| 640 | |||
| 641 | /** |
||
| 642 | * |
||
| 643 | * Sets the limit and count by page number. |
||
| 644 | * |
||
| 645 | * @param int $page Limit results to this page number. |
||
| 646 | * |
||
| 647 | * @return $this |
||
| 648 | * |
||
| 649 | */ |
||
| 650 | 20 | public function page($page) |
|
| 656 | |||
| 657 | /** |
||
| 658 | * |
||
| 659 | * Updates the limit and offset values when changing pagination. |
||
| 660 | * |
||
| 661 | * @return null |
||
| 662 | * |
||
| 663 | */ |
||
| 664 | 20 | protected function setPagingLimitOffset() |
|
| 673 | |||
| 674 | /** |
||
| 675 | * |
||
| 676 | * Returns the page number being selected. |
||
| 677 | * |
||
| 678 | * @return int |
||
| 679 | * |
||
| 680 | */ |
||
| 681 | public function getPage() |
||
| 685 | |||
| 686 | /** |
||
| 687 | * |
||
| 688 | * Takes the current select properties and retains them, then sets |
||
| 689 | * UNION for the next set of properties. |
||
| 690 | * |
||
| 691 | * @return $this |
||
| 692 | * |
||
| 693 | */ |
||
| 694 | 10 | public function union() |
|
| 700 | |||
| 701 | /** |
||
| 702 | * |
||
| 703 | * Takes the current select properties and retains them, then sets |
||
| 704 | * UNION ALL for the next set of properties. |
||
| 705 | * |
||
| 706 | * @return $this |
||
| 707 | * |
||
| 708 | */ |
||
| 709 | 5 | public function unionAll() |
|
| 715 | |||
| 716 | /** |
||
| 717 | * |
||
| 718 | * Returns the LIMIT value. |
||
| 719 | * |
||
| 720 | * @return int |
||
| 721 | * |
||
| 722 | */ |
||
| 723 | 5 | public function getLimit() |
|
| 727 | |||
| 728 | /** |
||
| 729 | * |
||
| 730 | * Returns the OFFSET value. |
||
| 731 | * |
||
| 732 | * @return int |
||
| 733 | * |
||
| 734 | */ |
||
| 735 | 5 | public function getOffset() |
|
| 739 | |||
| 740 | /** |
||
| 741 | * |
||
| 742 | * Clears the current select properties; generally used after adding a |
||
| 743 | * union. |
||
| 744 | * |
||
| 745 | * @return null |
||
| 746 | * |
||
| 747 | */ |
||
| 748 | 15 | protected function reset() |
|
| 762 | |||
| 763 | /** |
||
| 764 | * |
||
| 765 | * Resets the columns on the SELECT. |
||
| 766 | * |
||
| 767 | * @return $this |
||
| 768 | * |
||
| 769 | */ |
||
| 770 | 15 | public function resetCols() |
|
| 775 | |||
| 776 | /** |
||
| 777 | * |
||
| 778 | * Resets the FROM and JOIN clauses on the SELECT. |
||
| 779 | * |
||
| 780 | * @return $this |
||
| 781 | * |
||
| 782 | */ |
||
| 783 | 15 | public function resetTables() |
|
| 791 | |||
| 792 | /** |
||
| 793 | * |
||
| 794 | * Resets the WHERE clause on the SELECT. |
||
| 795 | * |
||
| 796 | * @return $this |
||
| 797 | * |
||
| 798 | */ |
||
| 799 | 15 | public function resetWhere() |
|
| 804 | |||
| 805 | /** |
||
| 806 | * |
||
| 807 | * Resets the GROUP BY clause on the SELECT. |
||
| 808 | * |
||
| 809 | * @return $this |
||
| 810 | * |
||
| 811 | */ |
||
| 812 | 15 | public function resetGroupBy() |
|
| 817 | |||
| 818 | /** |
||
| 819 | * |
||
| 820 | * Resets the HAVING clause on the SELECT. |
||
| 821 | * |
||
| 822 | * @return $this |
||
| 823 | * |
||
| 824 | */ |
||
| 825 | 15 | public function resetHaving() |
|
| 830 | |||
| 831 | /** |
||
| 832 | * |
||
| 833 | * Resets the ORDER BY clause on the SELECT. |
||
| 834 | * |
||
| 835 | * @return $this |
||
| 836 | * |
||
| 837 | */ |
||
| 838 | 15 | public function resetOrderBy() |
|
| 843 | |||
| 844 | /** |
||
| 845 | * |
||
| 846 | * Resets the UNION and UNION ALL clauses on the SELECT. |
||
| 847 | * |
||
| 848 | * @return $this |
||
| 849 | * |
||
| 850 | */ |
||
| 851 | public function resetUnions() |
||
| 856 | |||
| 857 | /** |
||
| 858 | * |
||
| 859 | * Builds this query object into a string. |
||
| 860 | * |
||
| 861 | * @return string |
||
| 862 | * |
||
| 863 | */ |
||
| 864 | 144 | protected function build() |
|
| 877 | |||
| 878 | /** |
||
| 879 | * |
||
| 880 | * Builds the columns clause. |
||
| 881 | * |
||
| 882 | * @return string |
||
| 883 | * |
||
| 884 | * @throws Exception when there are no columns in the SELECT. |
||
| 885 | * |
||
| 886 | */ |
||
| 887 | 144 | protected function buildCols() |
|
| 904 | |||
| 905 | /** |
||
| 906 | * |
||
| 907 | * Builds the FROM clause. |
||
| 908 | * |
||
| 909 | * @return string |
||
| 910 | * |
||
| 911 | */ |
||
| 912 | 139 | protected function buildFrom() |
|
| 927 | |||
| 928 | /** |
||
| 929 | * |
||
| 930 | * Builds the GROUP BY clause. |
||
| 931 | * |
||
| 932 | * @return string |
||
| 933 | * |
||
| 934 | */ |
||
| 935 | 139 | protected function buildGroupBy() |
|
| 943 | |||
| 944 | /** |
||
| 945 | * |
||
| 946 | * Builds the HAVING clause. |
||
| 947 | * |
||
| 948 | * @return string |
||
| 949 | * |
||
| 950 | */ |
||
| 951 | 139 | protected function buildHaving() |
|
| 959 | |||
| 960 | /** |
||
| 961 | * |
||
| 962 | * Builds the FOR UPDATE clause. |
||
| 963 | * |
||
| 964 | * @return string |
||
| 965 | * |
||
| 966 | */ |
||
| 967 | 139 | protected function buildForUpdate() |
|
| 975 | |||
| 976 | /** |
||
| 977 | * |
||
| 978 | * Adds a WHERE condition to the query by AND. If the condition has |
||
| 979 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 980 | * those placeholders sequentially. |
||
| 981 | * |
||
| 982 | * @param string $cond The WHERE condition. |
||
| 983 | * @param mixed ...$bind arguments to bind to placeholders |
||
| 984 | * |
||
| 985 | * @return $this |
||
| 986 | * |
||
| 987 | */ |
||
| 988 | 10 | public function where($cond) |
|
| 993 | |||
| 994 | /** |
||
| 995 | * |
||
| 996 | * Adds a WHERE condition to the query by OR. If the condition has |
||
| 997 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 998 | * those placeholders sequentially. |
||
| 999 | * |
||
| 1000 | * @param string $cond The WHERE condition. |
||
| 1001 | * @param mixed ...$bind arguments to bind to placeholders |
||
| 1002 | * |
||
| 1003 | * @return $this |
||
| 1004 | * |
||
| 1005 | * @see where() |
||
| 1006 | * |
||
| 1007 | */ |
||
| 1008 | public function orWhere($cond) |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * |
||
| 1016 | * Sets a limit count on the query. |
||
| 1017 | * |
||
| 1018 | * @param int $limit The number of rows to select. |
||
| 1019 | * |
||
| 1020 | * @return $this |
||
| 1021 | * |
||
| 1022 | */ |
||
| 1023 | 30 | public function limit($limit) |
|
| 1032 | |||
| 1033 | /** |
||
| 1034 | * |
||
| 1035 | * Sets a limit offset on the query. |
||
| 1036 | * |
||
| 1037 | * @param int $offset Start returning after this many rows. |
||
| 1038 | * |
||
| 1039 | * @return $this |
||
| 1040 | * |
||
| 1041 | */ |
||
| 1042 | 30 | public function offset($offset) |
|
| 1051 | |||
| 1052 | /** |
||
| 1053 | * |
||
| 1054 | * Adds a column order to the query. |
||
| 1055 | * |
||
| 1056 | * @param array $spec The columns and direction to order by. |
||
| 1057 | * |
||
| 1058 | * @return $this |
||
| 1059 | * |
||
| 1060 | */ |
||
| 1061 | 5 | public function orderBy(array $spec) |
|
| 1065 | } |
||
| 1066 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.