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 | 184 | public function getStatement() |
|
| 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 | 5 | $this->setPagingLimitOffset(); |
|
| 152 | 5 | } |
|
| 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 | 10 | 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 | } |
||
| 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 | 16 | public function distinct($enable = true) |
|
| 195 | { |
||
| 196 | 16 | $this->setFlag('DISTINCT', $enable); |
|
| 197 | 16 | return $this; |
|
| 198 | } |
||
| 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 | 224 | 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 | 224 | 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 | * @return null |
||
| 252 | * |
||
| 253 | */ |
||
| 254 | 214 | protected function addColWithAlias($spec) |
|
| 269 | |||
| 270 | /** |
||
| 271 | * |
||
| 272 | * Remove a column via its alias. |
||
| 273 | * |
||
| 274 | * @param string $alias The column to remove |
||
| 275 | * |
||
| 276 | * @return bool |
||
| 277 | * |
||
| 278 | */ |
||
| 279 | 15 | public function removeCol($alias) |
|
| 295 | |||
| 296 | /** |
||
| 297 | * |
||
| 298 | * Does the query have any columns in it? |
||
| 299 | * |
||
| 300 | * @return bool |
||
| 301 | * |
||
| 302 | */ |
||
| 303 | 5 | public function hasCols() |
|
| 307 | |||
| 308 | /** |
||
| 309 | * |
||
| 310 | * Returns a list of columns. |
||
| 311 | * |
||
| 312 | * @return array |
||
| 313 | * |
||
| 314 | */ |
||
| 315 | 15 | public function getCols() |
|
| 319 | |||
| 320 | /** |
||
| 321 | * |
||
| 322 | * Tracks table references. |
||
| 323 | * |
||
| 324 | * @param string $type FROM, JOIN, etc. |
||
| 325 | * |
||
| 326 | * @param string $spec The table and alias name. |
||
| 327 | * |
||
| 328 | * @return null |
||
| 329 | * |
||
| 330 | * @throws Exception when the reference has already been used. |
||
| 331 | * |
||
| 332 | */ |
||
| 333 | 149 | protected function addTableRef($type, $spec) |
|
| 349 | |||
| 350 | /** |
||
| 351 | * |
||
| 352 | * Adds a FROM element to the query; quotes the table name automatically. |
||
| 353 | * |
||
| 354 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 355 | * |
||
| 356 | * @return $this |
||
| 357 | * |
||
| 358 | */ |
||
| 359 | 139 | public function from($spec) |
|
| 364 | |||
| 365 | /** |
||
| 366 | * |
||
| 367 | * Adds a raw unquoted FROM element to the query; useful for adding FROM |
||
| 368 | * elements that are functions. |
||
| 369 | * |
||
| 370 | * @param string $spec The table specification, e.g. "function_name()". |
||
| 371 | * |
||
| 372 | * @return $this |
||
| 373 | * |
||
| 374 | */ |
||
| 375 | 5 | public function fromRaw($spec) |
|
| 380 | |||
| 381 | /** |
||
| 382 | * |
||
| 383 | * Adds to the $from property and increments the key count. |
||
| 384 | * |
||
| 385 | * @param string $spec The table specification. |
||
| 386 | * |
||
| 387 | * @return $this |
||
| 388 | * |
||
| 389 | */ |
||
| 390 | 149 | protected function addFrom($spec) |
|
| 396 | |||
| 397 | /** |
||
| 398 | * |
||
| 399 | * Adds an aliased sub-select to the query. |
||
| 400 | * |
||
| 401 | * @param string|Select $spec If a Select object, use as the sub-select; |
||
| 402 | * if a string, the sub-select string. |
||
| 403 | * |
||
| 404 | * @param string $name The alias name for the sub-select. |
||
| 405 | * |
||
| 406 | * @return $this |
||
| 407 | * |
||
| 408 | */ |
||
| 409 | 15 | public function fromSubSelect($spec, $name) |
|
| 416 | |||
| 417 | /** |
||
| 418 | * |
||
| 419 | * Formats a sub-SELECT statement, binding values from a Select object as |
||
| 420 | * needed. |
||
| 421 | * |
||
| 422 | * @param string|SelectInterface $spec A sub-SELECT specification. |
||
| 423 | * |
||
| 424 | * @param string $indent Indent each line with this string. |
||
| 425 | * |
||
| 426 | * @return string The sub-SELECT string. |
||
| 427 | * |
||
| 428 | */ |
||
| 429 | 25 | protected function subSelect($spec, $indent) |
|
| 439 | |||
| 440 | /** |
||
| 441 | * |
||
| 442 | * Adds a JOIN table and columns to the query. |
||
| 443 | * |
||
| 444 | * @param string $join The join type: inner, left, natural, etc. |
||
| 445 | * |
||
| 446 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 447 | * |
||
| 448 | * @param string $cond Join on this condition. |
||
| 449 | * |
||
| 450 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 451 | * |
||
| 452 | * @return $this |
||
| 453 | * |
||
| 454 | * @throws Exception |
||
| 455 | * |
||
| 456 | */ |
||
| 457 | 45 | public function join($join, $spec, $cond = null, array $bind = array()) |
|
| 466 | |||
| 467 | /** |
||
| 468 | * |
||
| 469 | * Fixes a JOIN condition to quote names in the condition and prefix it |
||
| 470 | * with a condition type ('ON' is the default and 'USING' is recognized). |
||
| 471 | * |
||
| 472 | * @param string $cond Join on this condition. |
||
| 473 | * |
||
| 474 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 475 | * |
||
| 476 | * @return string |
||
| 477 | * |
||
| 478 | */ |
||
| 479 | 55 | protected function fixJoinCondition($cond, array $bind) |
|
| 498 | |||
| 499 | /** |
||
| 500 | * |
||
| 501 | * Adds a INNER JOIN table and columns to the query. |
||
| 502 | * |
||
| 503 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 504 | * |
||
| 505 | * @param string $cond Join on this condition. |
||
| 506 | * |
||
| 507 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 508 | * |
||
| 509 | * @return $this |
||
| 510 | * |
||
| 511 | * @throws Exception |
||
| 512 | * |
||
| 513 | */ |
||
| 514 | 10 | public function innerJoin($spec, $cond = null, array $bind = array()) |
|
| 518 | |||
| 519 | /** |
||
| 520 | * |
||
| 521 | * Adds a LEFT JOIN table and columns to the query. |
||
| 522 | * |
||
| 523 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 524 | * |
||
| 525 | * @param string $cond Join on this condition. |
||
| 526 | * |
||
| 527 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 528 | * |
||
| 529 | * @return $this |
||
| 530 | * |
||
| 531 | * @throws Exception |
||
| 532 | * |
||
| 533 | */ |
||
| 534 | 10 | public function leftJoin($spec, $cond = null, array $bind = array()) |
|
| 538 | |||
| 539 | /** |
||
| 540 | * |
||
| 541 | * Adds a JOIN to an aliased subselect and columns to the query. |
||
| 542 | * |
||
| 543 | * @param string $join The join type: inner, left, natural, etc. |
||
| 544 | * |
||
| 545 | * @param string|Select $spec If a Select |
||
| 546 | * object, use as the sub-select; if a string, the sub-select |
||
| 547 | * command string. |
||
| 548 | * |
||
| 549 | * @param string $name The alias name for the sub-select. |
||
| 550 | * |
||
| 551 | * @param string $cond Join on this condition. |
||
| 552 | * |
||
| 553 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 554 | * |
||
| 555 | * @return $this |
||
| 556 | * |
||
| 557 | * @throws Exception |
||
| 558 | * |
||
| 559 | */ |
||
| 560 | 20 | public function joinSubSelect($join, $spec, $name, $cond = null, array $bind = array()) |
|
| 572 | |||
| 573 | /** |
||
| 574 | * |
||
| 575 | * Adds the JOIN to the right place, given whether or not a FROM has been |
||
| 576 | * specified yet. |
||
| 577 | * |
||
| 578 | * @param string $spec The JOIN clause. |
||
| 579 | * |
||
| 580 | * @return $this |
||
| 581 | * |
||
| 582 | */ |
||
| 583 | 55 | protected function addJoin($spec) |
|
| 589 | |||
| 590 | /** |
||
| 591 | * |
||
| 592 | * Adds grouping to the query. |
||
| 593 | * |
||
| 594 | * @param array $spec The column(s) to group by. |
||
| 595 | * |
||
| 596 | * @return $this |
||
| 597 | * |
||
| 598 | */ |
||
| 599 | 5 | public function groupBy(array $spec) |
|
| 606 | |||
| 607 | /** |
||
| 608 | * |
||
| 609 | * Adds a HAVING condition to the query by AND. If the condition has |
||
| 610 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 611 | * those placeholders sequentially. |
||
| 612 | * |
||
| 613 | * @param string $cond The HAVING condition. |
||
| 614 | * |
||
| 615 | * @param array ...$bind arguments to bind to placeholders |
||
| 616 | * |
||
| 617 | * @return $this |
||
| 618 | * |
||
| 619 | */ |
||
| 620 | 10 | public function having($cond, ...$bind) |
|
| 625 | |||
| 626 | /** |
||
| 627 | * |
||
| 628 | * Adds a HAVING condition to the query by AND. If the condition has |
||
| 629 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 630 | * those placeholders sequentially. |
||
| 631 | * |
||
| 632 | * @param string $cond The HAVING condition. |
||
| 633 | * |
||
| 634 | * @param array ...$bind arguments to bind to placeholders |
||
| 635 | * |
||
| 636 | * @return $this |
||
| 637 | * |
||
| 638 | * @see having() |
||
| 639 | * |
||
| 640 | */ |
||
| 641 | 5 | public function orHaving($cond, ...$bind) |
|
| 646 | |||
| 647 | /** |
||
| 648 | * |
||
| 649 | * Sets the limit and count by page number. |
||
| 650 | * |
||
| 651 | * @param int $page Limit results to this page number. |
||
| 652 | * |
||
| 653 | * @return $this |
||
| 654 | * |
||
| 655 | */ |
||
| 656 | 25 | public function page($page) |
|
| 662 | |||
| 663 | /** |
||
| 664 | * |
||
| 665 | * Updates the limit and offset values when changing pagination. |
||
| 666 | * |
||
| 667 | * @return null |
||
| 668 | * |
||
| 669 | */ |
||
| 670 | 25 | protected function setPagingLimitOffset() |
|
| 679 | |||
| 680 | /** |
||
| 681 | * |
||
| 682 | * Returns the page number being selected. |
||
| 683 | * |
||
| 684 | * @return int |
||
| 685 | * |
||
| 686 | */ |
||
| 687 | 5 | public function getPage() |
|
| 691 | |||
| 692 | /** |
||
| 693 | * |
||
| 694 | * Takes the current select properties and retains them, then sets |
||
| 695 | * UNION for the next set of properties. |
||
| 696 | * |
||
| 697 | * @return $this |
||
| 698 | * |
||
| 699 | */ |
||
| 700 | 10 | public function union() |
|
| 706 | |||
| 707 | /** |
||
| 708 | * |
||
| 709 | * Takes the current select properties and retains them, then sets |
||
| 710 | * UNION ALL for the next set of properties. |
||
| 711 | * |
||
| 712 | * @return $this |
||
| 713 | * |
||
| 714 | */ |
||
| 715 | 5 | public function unionAll() |
|
| 721 | |||
| 722 | /** |
||
| 723 | * |
||
| 724 | * Returns the LIMIT value. |
||
| 725 | * |
||
| 726 | * @return int |
||
| 727 | * |
||
| 728 | */ |
||
| 729 | 10 | public function getLimit() |
|
| 733 | |||
| 734 | /** |
||
| 735 | * |
||
| 736 | * Returns the OFFSET value. |
||
| 737 | * |
||
| 738 | * @return int |
||
| 739 | * |
||
| 740 | */ |
||
| 741 | 10 | public function getOffset() |
|
| 745 | |||
| 746 | /** |
||
| 747 | * |
||
| 748 | * Clears the current select properties; generally used after adding a |
||
| 749 | * union. |
||
| 750 | * |
||
| 751 | * @return null |
||
| 752 | * |
||
| 753 | */ |
||
| 754 | 15 | protected function reset() |
|
| 768 | |||
| 769 | /** |
||
| 770 | * |
||
| 771 | * Resets the columns on the SELECT. |
||
| 772 | * |
||
| 773 | * @return $this |
||
| 774 | * |
||
| 775 | */ |
||
| 776 | 15 | public function resetCols() |
|
| 781 | |||
| 782 | /** |
||
| 783 | * |
||
| 784 | * Resets the FROM and JOIN clauses on the SELECT. |
||
| 785 | * |
||
| 786 | * @return $this |
||
| 787 | * |
||
| 788 | */ |
||
| 789 | 15 | public function resetTables() |
|
| 797 | |||
| 798 | /** |
||
| 799 | * |
||
| 800 | * Resets the WHERE clause on the SELECT. |
||
| 801 | * |
||
| 802 | * @return $this |
||
| 803 | * |
||
| 804 | */ |
||
| 805 | 15 | public function resetWhere() |
|
| 810 | |||
| 811 | /** |
||
| 812 | * |
||
| 813 | * Resets the GROUP BY clause on the SELECT. |
||
| 814 | * |
||
| 815 | * @return $this |
||
| 816 | * |
||
| 817 | */ |
||
| 818 | 15 | public function resetGroupBy() |
|
| 823 | |||
| 824 | /** |
||
| 825 | * |
||
| 826 | * Resets the HAVING clause on the SELECT. |
||
| 827 | * |
||
| 828 | * @return $this |
||
| 829 | * |
||
| 830 | */ |
||
| 831 | 15 | public function resetHaving() |
|
| 836 | |||
| 837 | /** |
||
| 838 | * |
||
| 839 | * Resets the ORDER BY clause on the SELECT. |
||
| 840 | * |
||
| 841 | * @return $this |
||
| 842 | * |
||
| 843 | */ |
||
| 844 | 15 | public function resetOrderBy() |
|
| 849 | |||
| 850 | /** |
||
| 851 | * |
||
| 852 | * Resets the UNION and UNION ALL clauses on the SELECT. |
||
| 853 | * |
||
| 854 | * @return $this |
||
| 855 | * |
||
| 856 | */ |
||
| 857 | public function resetUnions() |
||
| 862 | |||
| 863 | /** |
||
| 864 | * |
||
| 865 | * Builds this query object into a string. |
||
| 866 | * |
||
| 867 | * @return string |
||
| 868 | * |
||
| 869 | */ |
||
| 870 | 184 | protected function build() |
|
| 883 | |||
| 884 | /** |
||
| 885 | * |
||
| 886 | * Builds the columns clause. |
||
| 887 | * |
||
| 888 | * @return string |
||
| 889 | * |
||
| 890 | * @throws Exception when there are no columns in the SELECT. |
||
| 891 | * |
||
| 892 | */ |
||
| 893 | 184 | protected function buildCols() |
|
| 910 | |||
| 911 | /** |
||
| 912 | * |
||
| 913 | * Builds the FROM clause. |
||
| 914 | * |
||
| 915 | * @return string |
||
| 916 | * |
||
| 917 | */ |
||
| 918 | 179 | protected function buildFrom() |
|
| 933 | |||
| 934 | /** |
||
| 935 | * |
||
| 936 | * Builds the GROUP BY clause. |
||
| 937 | * |
||
| 938 | * @return string |
||
| 939 | * |
||
| 940 | */ |
||
| 941 | 179 | protected function buildGroupBy() |
|
| 949 | |||
| 950 | /** |
||
| 951 | * |
||
| 952 | * Builds the HAVING clause. |
||
| 953 | * |
||
| 954 | * @return string |
||
| 955 | * |
||
| 956 | */ |
||
| 957 | 179 | protected function buildHaving() |
|
| 965 | |||
| 966 | /** |
||
| 967 | * |
||
| 968 | * Builds the FOR UPDATE clause. |
||
| 969 | * |
||
| 970 | * @return string |
||
| 971 | * |
||
| 972 | */ |
||
| 973 | 179 | protected function buildForUpdate() |
|
| 981 | |||
| 982 | /** |
||
| 983 | * |
||
| 984 | * Adds a WHERE condition to the query by AND. If the condition has |
||
| 985 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 986 | * those placeholders sequentially. |
||
| 987 | * |
||
| 988 | * @param string $cond The WHERE condition. |
||
| 989 | * @param mixed ...$bind arguments to bind to placeholders |
||
| 990 | * |
||
| 991 | * @return $this |
||
| 992 | * |
||
| 993 | */ |
||
| 994 | 30 | public function where($cond, ...$bind) |
|
| 999 | |||
| 1000 | /** |
||
| 1001 | * |
||
| 1002 | * Adds a WHERE condition to the query by OR. If the condition has |
||
| 1003 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 1004 | * those placeholders sequentially. |
||
| 1005 | * |
||
| 1006 | * @param string $cond The WHERE condition. |
||
| 1007 | * @param mixed ...$bind arguments to bind to placeholders |
||
| 1008 | * |
||
| 1009 | * @return $this |
||
| 1010 | * |
||
| 1011 | * @see where() |
||
| 1012 | * |
||
| 1013 | */ |
||
| 1014 | 5 | public function orWhere($cond, ...$bind) |
|
| 1019 | |||
| 1020 | /** |
||
| 1021 | * |
||
| 1022 | * Sets a limit count on the query. |
||
| 1023 | * |
||
| 1024 | * @param int $limit The number of rows to select. |
||
| 1025 | * |
||
| 1026 | * @return $this |
||
| 1027 | * |
||
| 1028 | */ |
||
| 1029 | 30 | public function limit($limit) |
|
| 1038 | |||
| 1039 | /** |
||
| 1040 | * |
||
| 1041 | * Sets a limit offset on the query. |
||
| 1042 | * |
||
| 1043 | * @param int $offset Start returning after this many rows. |
||
| 1044 | * |
||
| 1045 | * @return $this |
||
| 1046 | * |
||
| 1047 | */ |
||
| 1048 | 30 | public function offset($offset) |
|
| 1057 | |||
| 1058 | /** |
||
| 1059 | * |
||
| 1060 | * Adds a column order to the query. |
||
| 1061 | * |
||
| 1062 | * @param array $spec The columns and direction to order by. |
||
| 1063 | * |
||
| 1064 | * @return $this |
||
| 1065 | * |
||
| 1066 | */ |
||
| 1067 | 5 | public function orderBy(array $spec) |
|
| 1071 | } |
||
| 1072 |
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.