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) |
|
| 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) |
|
| 199 | |||
| 200 | /** |
||
| 201 | * |
||
| 202 | * Is the select DISTINCT? |
||
| 203 | * |
||
| 204 | * @return bool |
||
| 205 | * |
||
| 206 | */ |
||
| 207 | 10 | public function isDistinct() |
|
| 211 | |||
| 212 | /** |
||
| 213 | * |
||
| 214 | * Adds columns to the query. |
||
| 215 | * |
||
| 216 | * Multiple calls to cols() will append to the list of columns, not |
||
| 217 | * overwrite the previous columns. |
||
| 218 | * |
||
| 219 | * @param array $cols The column(s) to add to the query. The elements can be |
||
| 220 | * any mix of these: `array("col", "col AS alias", "col" => "alias")` |
||
| 221 | * |
||
| 222 | * @return $this |
||
| 223 | * |
||
| 224 | */ |
||
| 225 | 224 | public function cols(array $cols) |
|
| 232 | |||
| 233 | /** |
||
| 234 | * |
||
| 235 | * Adds a column and alias to the columns to be selected. |
||
| 236 | * |
||
| 237 | * @param mixed $key If an integer, ignored. Otherwise, the column to be |
||
| 238 | * added. |
||
| 239 | * |
||
| 240 | * @param mixed $val If $key was an integer, the column to be added; |
||
| 241 | * otherwise, the column alias. |
||
| 242 | * |
||
| 243 | * @return null |
||
| 244 | * |
||
| 245 | */ |
||
| 246 | 224 | protected function addCol($key, $val) |
|
| 255 | |||
| 256 | /** |
||
| 257 | * |
||
| 258 | * Adds a column with an alias to the columns to be selected. |
||
| 259 | * |
||
| 260 | * @param string $spec The column specification: "col alias", |
||
| 261 | * "col AS alias", or something else entirely. |
||
| 262 | * |
||
| 263 | * @return null |
||
| 264 | * |
||
| 265 | */ |
||
| 266 | 214 | protected function addColWithAlias($spec) |
|
| 281 | |||
| 282 | /** |
||
| 283 | * |
||
| 284 | * Remove a column via its alias. |
||
| 285 | * |
||
| 286 | * @param string $alias The column to remove |
||
| 287 | * |
||
| 288 | * @return bool |
||
| 289 | * |
||
| 290 | */ |
||
| 291 | 15 | public function removeCol($alias) |
|
| 307 | |||
| 308 | /** |
||
| 309 | * |
||
| 310 | * Has the column or alias been added to the query? |
||
| 311 | * |
||
| 312 | * @param string $alias The column or alias to look for |
||
| 313 | * |
||
| 314 | * @return bool |
||
| 315 | * |
||
| 316 | */ |
||
| 317 | 5 | public function hasCol($alias) |
|
| 321 | |||
| 322 | /** |
||
| 323 | * |
||
| 324 | * Does the query have any columns in it? |
||
| 325 | * |
||
| 326 | * @return bool |
||
| 327 | * |
||
| 328 | */ |
||
| 329 | 5 | public function hasCols() |
|
| 333 | |||
| 334 | /** |
||
| 335 | * |
||
| 336 | * Returns a list of columns. |
||
| 337 | * |
||
| 338 | * @return array |
||
| 339 | * |
||
| 340 | */ |
||
| 341 | 15 | public function getCols() |
|
| 345 | |||
| 346 | /** |
||
| 347 | * |
||
| 348 | * Tracks table references. |
||
| 349 | * |
||
| 350 | * @param string $type FROM, JOIN, etc. |
||
| 351 | * |
||
| 352 | * @param string $spec The table and alias name. |
||
| 353 | * |
||
| 354 | * @return null |
||
| 355 | * |
||
| 356 | * @throws Exception when the reference has already been used. |
||
| 357 | * |
||
| 358 | */ |
||
| 359 | 149 | protected function addTableRef($type, $spec) |
|
| 375 | |||
| 376 | /** |
||
| 377 | * |
||
| 378 | * Adds a FROM element to the query; quotes the table name automatically. |
||
| 379 | * |
||
| 380 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 381 | * |
||
| 382 | * @return $this |
||
| 383 | * |
||
| 384 | */ |
||
| 385 | 139 | public function from($spec) |
|
| 390 | |||
| 391 | /** |
||
| 392 | * |
||
| 393 | * Adds a raw unquoted FROM element to the query; useful for adding FROM |
||
| 394 | * elements that are functions. |
||
| 395 | * |
||
| 396 | * @param string $spec The table specification, e.g. "function_name()". |
||
| 397 | * |
||
| 398 | * @return $this |
||
| 399 | * |
||
| 400 | */ |
||
| 401 | 5 | public function fromRaw($spec) |
|
| 406 | |||
| 407 | /** |
||
| 408 | * |
||
| 409 | * Adds to the $from property and increments the key count. |
||
| 410 | * |
||
| 411 | * @param string $spec The table specification. |
||
| 412 | * |
||
| 413 | * @return $this |
||
| 414 | * |
||
| 415 | */ |
||
| 416 | 149 | protected function addFrom($spec) |
|
| 422 | |||
| 423 | /** |
||
| 424 | * |
||
| 425 | * Adds an aliased sub-select to the query. |
||
| 426 | * |
||
| 427 | * @param string|Select $spec If a Select object, use as the sub-select; |
||
| 428 | * if a string, the sub-select string. |
||
| 429 | * |
||
| 430 | * @param string $name The alias name for the sub-select. |
||
| 431 | * |
||
| 432 | * @return $this |
||
| 433 | * |
||
| 434 | */ |
||
| 435 | 15 | public function fromSubSelect($spec, $name) |
|
| 442 | |||
| 443 | /** |
||
| 444 | * |
||
| 445 | * Formats a sub-SELECT statement, binding values from a Select object as |
||
| 446 | * needed. |
||
| 447 | * |
||
| 448 | * @param string|SelectInterface $spec A sub-SELECT specification. |
||
| 449 | * |
||
| 450 | * @param string $indent Indent each line with this string. |
||
| 451 | * |
||
| 452 | * @return string The sub-SELECT string. |
||
| 453 | * |
||
| 454 | */ |
||
| 455 | 25 | protected function subSelect($spec, $indent) |
|
| 465 | |||
| 466 | /** |
||
| 467 | * |
||
| 468 | * Adds a JOIN table and columns to the query. |
||
| 469 | * |
||
| 470 | * @param string $join The join type: inner, left, natural, etc. |
||
| 471 | * |
||
| 472 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 473 | * |
||
| 474 | * @param string $cond Join on this condition. |
||
| 475 | * |
||
| 476 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 477 | * |
||
| 478 | * @return $this |
||
| 479 | * |
||
| 480 | * @throws Exception |
||
| 481 | * |
||
| 482 | */ |
||
| 483 | 45 | public function join($join, $spec, $cond = null, array $bind = array()) |
|
| 492 | |||
| 493 | /** |
||
| 494 | * |
||
| 495 | * Fixes a JOIN condition to quote names in the condition and prefix it |
||
| 496 | * with a condition type ('ON' is the default and 'USING' is recognized). |
||
| 497 | * |
||
| 498 | * @param string $cond Join on this condition. |
||
| 499 | * |
||
| 500 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 501 | * |
||
| 502 | * @return string |
||
| 503 | * |
||
| 504 | */ |
||
| 505 | 55 | protected function fixJoinCondition($cond, array $bind) |
|
| 524 | |||
| 525 | /** |
||
| 526 | * |
||
| 527 | * Adds a INNER JOIN table and columns to the query. |
||
| 528 | * |
||
| 529 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 530 | * |
||
| 531 | * @param string $cond Join on this condition. |
||
| 532 | * |
||
| 533 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 534 | * |
||
| 535 | * @return $this |
||
| 536 | * |
||
| 537 | * @throws Exception |
||
| 538 | * |
||
| 539 | */ |
||
| 540 | 10 | public function innerJoin($spec, $cond = null, array $bind = array()) |
|
| 544 | |||
| 545 | /** |
||
| 546 | * |
||
| 547 | * Adds a LEFT JOIN table and columns to the query. |
||
| 548 | * |
||
| 549 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 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 | 10 | public function leftJoin($spec, $cond = null, array $bind = array()) |
|
| 564 | |||
| 565 | /** |
||
| 566 | * |
||
| 567 | * Adds a JOIN to an aliased subselect and columns to the query. |
||
| 568 | * |
||
| 569 | * @param string $join The join type: inner, left, natural, etc. |
||
| 570 | * |
||
| 571 | * @param string|Select $spec If a Select |
||
| 572 | * object, use as the sub-select; if a string, the sub-select |
||
| 573 | * command string. |
||
| 574 | * |
||
| 575 | * @param string $name The alias name for the sub-select. |
||
| 576 | * |
||
| 577 | * @param string $cond Join on this condition. |
||
| 578 | * |
||
| 579 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 580 | * |
||
| 581 | * @return $this |
||
| 582 | * |
||
| 583 | * @throws Exception |
||
| 584 | * |
||
| 585 | */ |
||
| 586 | 20 | public function joinSubSelect($join, $spec, $name, $cond = null, array $bind = array()) |
|
| 598 | |||
| 599 | /** |
||
| 600 | * |
||
| 601 | * Adds the JOIN to the right place, given whether or not a FROM has been |
||
| 602 | * specified yet. |
||
| 603 | * |
||
| 604 | * @param string $spec The JOIN clause. |
||
| 605 | * |
||
| 606 | * @return $this |
||
| 607 | * |
||
| 608 | */ |
||
| 609 | 55 | protected function addJoin($spec) |
|
| 615 | |||
| 616 | /** |
||
| 617 | * |
||
| 618 | * Adds grouping to the query. |
||
| 619 | * |
||
| 620 | * @param array $spec The column(s) to group by. |
||
| 621 | * |
||
| 622 | * @return $this |
||
| 623 | * |
||
| 624 | */ |
||
| 625 | 5 | public function groupBy(array $spec) |
|
| 632 | |||
| 633 | /** |
||
| 634 | * |
||
| 635 | * Adds a HAVING condition to the query by AND. If the condition has |
||
| 636 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 637 | * those placeholders sequentially. |
||
| 638 | * |
||
| 639 | * @param string $cond The HAVING condition. |
||
| 640 | * |
||
| 641 | * @param array ...$bind arguments to bind to placeholders |
||
| 642 | * |
||
| 643 | * @return $this |
||
| 644 | * |
||
| 645 | */ |
||
| 646 | 10 | public function having($cond, ...$bind) |
|
| 651 | |||
| 652 | /** |
||
| 653 | * |
||
| 654 | * Adds a HAVING condition to the query by AND. If the condition has |
||
| 655 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 656 | * those placeholders sequentially. |
||
| 657 | * |
||
| 658 | * @param string $cond The HAVING condition. |
||
| 659 | * |
||
| 660 | * @param array ...$bind arguments to bind to placeholders |
||
| 661 | * |
||
| 662 | * @return $this |
||
| 663 | * |
||
| 664 | * @see having() |
||
| 665 | * |
||
| 666 | */ |
||
| 667 | 5 | public function orHaving($cond, ...$bind) |
|
| 672 | |||
| 673 | /** |
||
| 674 | * |
||
| 675 | * Sets the limit and count by page number. |
||
| 676 | * |
||
| 677 | * @param int $page Limit results to this page number. |
||
| 678 | * |
||
| 679 | * @return $this |
||
| 680 | * |
||
| 681 | */ |
||
| 682 | 25 | public function page($page) |
|
| 688 | |||
| 689 | /** |
||
| 690 | * |
||
| 691 | * Updates the limit and offset values when changing pagination. |
||
| 692 | * |
||
| 693 | * @return null |
||
| 694 | * |
||
| 695 | */ |
||
| 696 | 25 | protected function setPagingLimitOffset() |
|
| 705 | |||
| 706 | /** |
||
| 707 | * |
||
| 708 | * Returns the page number being selected. |
||
| 709 | * |
||
| 710 | * @return int |
||
| 711 | * |
||
| 712 | */ |
||
| 713 | 5 | public function getPage() |
|
| 717 | |||
| 718 | /** |
||
| 719 | * |
||
| 720 | * Takes the current select properties and retains them, then sets |
||
| 721 | * UNION for the next set of properties. |
||
| 722 | * |
||
| 723 | * @return $this |
||
| 724 | * |
||
| 725 | */ |
||
| 726 | 10 | public function union() |
|
| 732 | |||
| 733 | /** |
||
| 734 | * |
||
| 735 | * Takes the current select properties and retains them, then sets |
||
| 736 | * UNION ALL for the next set of properties. |
||
| 737 | * |
||
| 738 | * @return $this |
||
| 739 | * |
||
| 740 | */ |
||
| 741 | 5 | public function unionAll() |
|
| 747 | |||
| 748 | /** |
||
| 749 | * |
||
| 750 | * Returns the LIMIT value. |
||
| 751 | * |
||
| 752 | * @return int |
||
| 753 | * |
||
| 754 | */ |
||
| 755 | 10 | public function getLimit() |
|
| 759 | |||
| 760 | /** |
||
| 761 | * |
||
| 762 | * Returns the OFFSET value. |
||
| 763 | * |
||
| 764 | * @return int |
||
| 765 | * |
||
| 766 | */ |
||
| 767 | 10 | public function getOffset() |
|
| 771 | |||
| 772 | /** |
||
| 773 | * |
||
| 774 | * Clears the current select properties; generally used after adding a |
||
| 775 | * union. |
||
| 776 | * |
||
| 777 | * @return null |
||
| 778 | * |
||
| 779 | */ |
||
| 780 | 15 | public function reset() |
|
| 794 | |||
| 795 | /** |
||
| 796 | * |
||
| 797 | * Resets the columns on the SELECT. |
||
| 798 | * |
||
| 799 | * @return $this |
||
| 800 | * |
||
| 801 | */ |
||
| 802 | 15 | public function resetCols() |
|
| 807 | |||
| 808 | /** |
||
| 809 | * |
||
| 810 | * Resets the FROM and JOIN clauses on the SELECT. |
||
| 811 | * |
||
| 812 | * @return $this |
||
| 813 | * |
||
| 814 | */ |
||
| 815 | 15 | public function resetTables() |
|
| 823 | |||
| 824 | /** |
||
| 825 | * |
||
| 826 | * Resets the WHERE clause on the SELECT. |
||
| 827 | * |
||
| 828 | * @return $this |
||
| 829 | * |
||
| 830 | */ |
||
| 831 | 15 | public function resetWhere() |
|
| 836 | |||
| 837 | /** |
||
| 838 | * |
||
| 839 | * Resets the GROUP BY clause on the SELECT. |
||
| 840 | * |
||
| 841 | * @return $this |
||
| 842 | * |
||
| 843 | */ |
||
| 844 | 15 | public function resetGroupBy() |
|
| 849 | |||
| 850 | /** |
||
| 851 | * |
||
| 852 | * Resets the HAVING clause on the SELECT. |
||
| 853 | * |
||
| 854 | * @return $this |
||
| 855 | * |
||
| 856 | */ |
||
| 857 | 15 | public function resetHaving() |
|
| 862 | |||
| 863 | /** |
||
| 864 | * |
||
| 865 | * Resets the ORDER BY clause on the SELECT. |
||
| 866 | * |
||
| 867 | * @return $this |
||
| 868 | * |
||
| 869 | */ |
||
| 870 | 15 | public function resetOrderBy() |
|
| 875 | |||
| 876 | /** |
||
| 877 | * |
||
| 878 | * Resets the UNION and UNION ALL clauses on the SELECT. |
||
| 879 | * |
||
| 880 | * @return $this |
||
| 881 | * |
||
| 882 | */ |
||
| 883 | public function resetUnions() |
||
| 888 | |||
| 889 | /** |
||
| 890 | * |
||
| 891 | * Builds this query object into a string. |
||
| 892 | * |
||
| 893 | * @return string |
||
| 894 | * |
||
| 895 | */ |
||
| 896 | 184 | protected function build() |
|
| 909 | |||
| 910 | /** |
||
| 911 | * |
||
| 912 | * Builds the columns clause. |
||
| 913 | * |
||
| 914 | * @return string |
||
| 915 | * |
||
| 916 | * @throws Exception when there are no columns in the SELECT. |
||
| 917 | * |
||
| 918 | */ |
||
| 919 | 184 | protected function buildCols() |
|
| 936 | |||
| 937 | /** |
||
| 938 | * |
||
| 939 | * Builds the FROM clause. |
||
| 940 | * |
||
| 941 | * @return string |
||
| 942 | * |
||
| 943 | */ |
||
| 944 | 179 | protected function buildFrom() |
|
| 959 | |||
| 960 | /** |
||
| 961 | * |
||
| 962 | * Builds the GROUP BY clause. |
||
| 963 | * |
||
| 964 | * @return string |
||
| 965 | * |
||
| 966 | */ |
||
| 967 | 179 | protected function buildGroupBy() |
|
| 975 | |||
| 976 | /** |
||
| 977 | * |
||
| 978 | * Builds the HAVING clause. |
||
| 979 | * |
||
| 980 | * @return string |
||
| 981 | * |
||
| 982 | */ |
||
| 983 | 179 | protected function buildHaving() |
|
| 991 | |||
| 992 | /** |
||
| 993 | * |
||
| 994 | * Builds the FOR UPDATE clause. |
||
| 995 | * |
||
| 996 | * @return string |
||
| 997 | * |
||
| 998 | */ |
||
| 999 | 179 | protected function buildForUpdate() |
|
| 1007 | |||
| 1008 | /** |
||
| 1009 | * |
||
| 1010 | * Adds a WHERE condition to the query by AND. If the condition has |
||
| 1011 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 1012 | * those placeholders sequentially. |
||
| 1013 | * |
||
| 1014 | * @param string $cond The WHERE condition. |
||
| 1015 | * @param mixed ...$bind arguments to bind to placeholders |
||
| 1016 | * |
||
| 1017 | * @return $this |
||
| 1018 | * |
||
| 1019 | */ |
||
| 1020 | 30 | public function where($cond, ...$bind) |
|
| 1025 | |||
| 1026 | /** |
||
| 1027 | * |
||
| 1028 | * Adds a WHERE condition to the query by OR. If the condition has |
||
| 1029 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 1030 | * those placeholders sequentially. |
||
| 1031 | * |
||
| 1032 | * @param string $cond The WHERE condition. |
||
| 1033 | * @param mixed ...$bind arguments to bind to placeholders |
||
| 1034 | * |
||
| 1035 | * @return $this |
||
| 1036 | * |
||
| 1037 | * @see where() |
||
| 1038 | * |
||
| 1039 | */ |
||
| 1040 | 5 | public function orWhere($cond, ...$bind) |
|
| 1045 | |||
| 1046 | /** |
||
| 1047 | * |
||
| 1048 | * Sets a limit count on the query. |
||
| 1049 | * |
||
| 1050 | * @param int $limit The number of rows to select. |
||
| 1051 | * |
||
| 1052 | * @return $this |
||
| 1053 | * |
||
| 1054 | */ |
||
| 1055 | 30 | public function limit($limit) |
|
| 1064 | |||
| 1065 | /** |
||
| 1066 | * |
||
| 1067 | * Sets a limit offset on the query. |
||
| 1068 | * |
||
| 1069 | * @param int $offset Start returning after this many rows. |
||
| 1070 | * |
||
| 1071 | * @return $this |
||
| 1072 | * |
||
| 1073 | */ |
||
| 1074 | 30 | public function offset($offset) |
|
| 1083 | |||
| 1084 | /** |
||
| 1085 | * |
||
| 1086 | * Adds a column order to the query. |
||
| 1087 | * |
||
| 1088 | * @param array $spec The columns and direction to order by. |
||
| 1089 | * |
||
| 1090 | * @return $this |
||
| 1091 | * |
||
| 1092 | */ |
||
| 1093 | 5 | public function orderBy(array $spec) |
|
| 1097 | } |
||
| 1098 |
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.