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 | * GROUP BY these columns. |
||
| 71 | * |
||
| 72 | * @var array |
||
| 73 | * |
||
| 74 | */ |
||
| 75 | protected $group_by = array(); |
||
| 76 | |||
| 77 | /** |
||
| 78 | * |
||
| 79 | * The list of HAVING conditions. |
||
| 80 | * |
||
| 81 | * @var array |
||
| 82 | * |
||
| 83 | */ |
||
| 84 | protected $having = array(); |
||
| 85 | |||
| 86 | /** |
||
| 87 | * |
||
| 88 | * The page number to select. |
||
| 89 | * |
||
| 90 | * @var int |
||
| 91 | * |
||
| 92 | */ |
||
| 93 | protected $page = 0; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * |
||
| 97 | * The number of rows per page. |
||
| 98 | * |
||
| 99 | * @var int |
||
| 100 | * |
||
| 101 | */ |
||
| 102 | protected $paging = 10; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * |
||
| 106 | * Tracks table references to avoid duplicate identifiers. |
||
| 107 | * |
||
| 108 | * @var array |
||
| 109 | * |
||
| 110 | */ |
||
| 111 | protected $table_refs = array(); |
||
| 112 | |||
| 113 | /** |
||
| 114 | * |
||
| 115 | * Returns this query object as an SQL statement string. |
||
| 116 | * |
||
| 117 | * @return string An SQL statement string. |
||
| 118 | * |
||
| 119 | */ |
||
| 120 | 174 | public function getStatement() |
|
| 121 | { |
||
| 122 | 174 | $union = ''; |
|
| 123 | 174 | if ($this->union) { |
|
|
|
|||
| 124 | 15 | $union = implode(PHP_EOL, $this->union) . PHP_EOL; |
|
| 125 | } |
||
| 126 | 174 | return $union . $this->build(); |
|
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * |
||
| 131 | * Sets the number of rows per page. |
||
| 132 | * |
||
| 133 | * @param int $paging The number of rows to page at. |
||
| 134 | * |
||
| 135 | * @return $this |
||
| 136 | * |
||
| 137 | */ |
||
| 138 | 10 | public function setPaging($paging) |
|
| 139 | { |
||
| 140 | 10 | $this->paging = (int) $paging; |
|
| 141 | 10 | if ($this->page) { |
|
| 142 | 5 | $this->setPagingLimitOffset(); |
|
| 143 | } |
||
| 144 | 10 | return $this; |
|
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * |
||
| 149 | * Gets the number of rows per page. |
||
| 150 | * |
||
| 151 | * @return int The number of rows per page. |
||
| 152 | * |
||
| 153 | */ |
||
| 154 | 10 | public function getPaging() |
|
| 158 | |||
| 159 | /** |
||
| 160 | * |
||
| 161 | * Makes the select FOR UPDATE (or not). |
||
| 162 | * |
||
| 163 | * @param bool $enable Whether or not the SELECT is FOR UPDATE (default |
||
| 164 | * true). |
||
| 165 | * |
||
| 166 | * @return $this |
||
| 167 | * |
||
| 168 | */ |
||
| 169 | 20 | public function forUpdate($enable = true) |
|
| 174 | |||
| 175 | /** |
||
| 176 | * |
||
| 177 | * Makes the select DISTINCT (or not). |
||
| 178 | * |
||
| 179 | * @param bool $enable Whether or not the SELECT is DISTINCT (default |
||
| 180 | * true). |
||
| 181 | * |
||
| 182 | * @return $this |
||
| 183 | * |
||
| 184 | */ |
||
| 185 | 16 | public function distinct($enable = true) |
|
| 190 | |||
| 191 | /** |
||
| 192 | * |
||
| 193 | * Adds columns to the query. |
||
| 194 | * |
||
| 195 | * Multiple calls to cols() will append to the list of columns, not |
||
| 196 | * overwrite the previous columns. |
||
| 197 | * |
||
| 198 | * @param array $cols The column(s) to add to the query. The elements can be |
||
| 199 | * any mix of these: `array("col", "col AS alias", "col" => "alias")` |
||
| 200 | * |
||
| 201 | * @return $this |
||
| 202 | * |
||
| 203 | */ |
||
| 204 | 214 | public function cols(array $cols) |
|
| 205 | { |
||
| 206 | 214 | foreach ($cols as $key => $val) { |
|
| 207 | 214 | $this->addCol($key, $val); |
|
| 208 | } |
||
| 209 | 214 | return $this; |
|
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | * |
||
| 214 | * Adds a column and alias to the columns to be selected. |
||
| 215 | * |
||
| 216 | * @param mixed $key If an integer, ignored. Otherwise, the column to be |
||
| 217 | * added. |
||
| 218 | * |
||
| 219 | * @param mixed $val If $key was an integer, the column to be added; |
||
| 220 | * otherwise, the column alias. |
||
| 221 | * |
||
| 222 | * @return null |
||
| 223 | * |
||
| 224 | */ |
||
| 225 | 214 | protected function addCol($key, $val) |
|
| 226 | { |
||
| 227 | 214 | if (is_string($key)) { |
|
| 228 | // [col => alias] |
||
| 229 | 25 | $this->cols[$val] = $key; |
|
| 230 | } else { |
||
| 231 | 204 | $this->addColWithAlias($val); |
|
| 232 | } |
||
| 233 | 214 | } |
|
| 234 | |||
| 235 | /** |
||
| 236 | * |
||
| 237 | * Adds a column with an alias to the columns to be selected. |
||
| 238 | * |
||
| 239 | * @param string $spec The column specification: "col alias", |
||
| 240 | * "col AS alias", or something else entirely. |
||
| 241 | * |
||
| 242 | * @return null |
||
| 243 | * |
||
| 244 | */ |
||
| 245 | 204 | protected function addColWithAlias($spec) |
|
| 246 | { |
||
| 247 | 204 | $parts = explode(' ', $spec); |
|
| 248 | 204 | $count = count($parts); |
|
| 249 | 204 | if ($count == 2) { |
|
| 250 | // "col alias" |
||
| 251 | 5 | $this->cols[$parts[1]] = $parts[0]; |
|
| 252 | 204 | } elseif ($count == 3 && strtoupper($parts[1]) == 'AS') { |
|
| 253 | // "col AS alias" |
||
| 254 | 5 | $this->cols[$parts[2]] = $parts[0]; |
|
| 255 | } else { |
||
| 256 | // no recognized alias |
||
| 257 | 204 | $this->cols[] = $spec; |
|
| 258 | } |
||
| 259 | 204 | } |
|
| 260 | |||
| 261 | /** |
||
| 262 | * |
||
| 263 | * Remove a column via its alias. |
||
| 264 | * |
||
| 265 | * @param string $alias The column to remove |
||
| 266 | * |
||
| 267 | * @return null |
||
| 268 | * |
||
| 269 | */ |
||
| 270 | 15 | public function removeCol($alias) |
|
| 286 | |||
| 287 | /** |
||
| 288 | * |
||
| 289 | * Does the query have any columns in it? |
||
| 290 | * |
||
| 291 | * @return bool |
||
| 292 | * |
||
| 293 | */ |
||
| 294 | 5 | public function hasCols() |
|
| 298 | |||
| 299 | /** |
||
| 300 | * |
||
| 301 | * Returns a list of columns. |
||
| 302 | * |
||
| 303 | * @return array |
||
| 304 | * |
||
| 305 | */ |
||
| 306 | 15 | public function getCols() |
|
| 310 | |||
| 311 | /** |
||
| 312 | * |
||
| 313 | * Tracks table references. |
||
| 314 | * |
||
| 315 | * @param string $type FROM, JOIN, etc. |
||
| 316 | * |
||
| 317 | * @param string $spec The table and alias name. |
||
| 318 | * |
||
| 319 | * @return null |
||
| 320 | * |
||
| 321 | * @throws Exception when the reference has already been used. |
||
| 322 | * |
||
| 323 | */ |
||
| 324 | 139 | protected function addTableRef($type, $spec) |
|
| 325 | { |
||
| 326 | 139 | $name = $spec; |
|
| 327 | |||
| 328 | 139 | $pos = strripos($name, ' AS '); |
|
| 329 | 139 | if ($pos !== false) { |
|
| 330 | 30 | $name = trim(substr($name, $pos + 4)); |
|
| 331 | } |
||
| 332 | |||
| 333 | 139 | if (isset($this->table_refs[$name])) { |
|
| 334 | 25 | $used = $this->table_refs[$name]; |
|
| 335 | 25 | throw new Exception("Cannot reference '$type $spec' after '$used'"); |
|
| 336 | } |
||
| 337 | |||
| 338 | 139 | $this->table_refs[$name] = "$type $spec"; |
|
| 339 | 139 | } |
|
| 340 | |||
| 341 | /** |
||
| 342 | * |
||
| 343 | * Adds a FROM element to the query; quotes the table name automatically. |
||
| 344 | * |
||
| 345 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 346 | * |
||
| 347 | * @return $this |
||
| 348 | * |
||
| 349 | */ |
||
| 350 | 129 | public function from($spec) |
|
| 355 | |||
| 356 | /** |
||
| 357 | * |
||
| 358 | * Adds a raw unquoted FROM element to the query; useful for adding FROM |
||
| 359 | * elements that are functions. |
||
| 360 | * |
||
| 361 | * @param string $spec The table specification, e.g. "function_name()". |
||
| 362 | * |
||
| 363 | * @return $this |
||
| 364 | * |
||
| 365 | */ |
||
| 366 | 5 | public function fromRaw($spec) |
|
| 371 | |||
| 372 | /** |
||
| 373 | * |
||
| 374 | * Adds to the $from property and increments the key count. |
||
| 375 | * |
||
| 376 | * @param string $spec The table specification. |
||
| 377 | * |
||
| 378 | * @return $this |
||
| 379 | * |
||
| 380 | */ |
||
| 381 | 134 | protected function addFrom($spec) |
|
| 387 | |||
| 388 | /** |
||
| 389 | * |
||
| 390 | * Adds an aliased sub-select to the query. |
||
| 391 | * |
||
| 392 | * @param string|Select $spec If a Select object, use as the sub-select; |
||
| 393 | * if a string, the sub-select string. |
||
| 394 | * |
||
| 395 | * @param string $name The alias name for the sub-select. |
||
| 396 | * |
||
| 397 | * @return $this |
||
| 398 | * |
||
| 399 | */ |
||
| 400 | 15 | public function fromSubSelect($spec, $name) |
|
| 409 | |||
| 410 | /** |
||
| 411 | * |
||
| 412 | * Formats a sub-SELECT statement, binding values from a Select object as |
||
| 413 | * needed. |
||
| 414 | * |
||
| 415 | * @param string|SelectInterface $spec A sub-SELECT specification. |
||
| 416 | * |
||
| 417 | * @param string $indent Indent each line with this string. |
||
| 418 | * |
||
| 419 | * @return string The sub-SELECT string. |
||
| 420 | * |
||
| 421 | */ |
||
| 422 | 20 | protected function subSelect($spec, $indent) |
|
| 423 | { |
||
| 424 | 20 | if ($spec instanceof SelectInterface) { |
|
| 425 | 10 | $this->bindValues($spec->getBindValues()); |
|
| 426 | } |
||
| 427 | |||
| 428 | 20 | return PHP_EOL . $indent |
|
| 429 | 20 | . ltrim(preg_replace('/^/m', $indent, (string) $spec)) |
|
| 430 | 20 | . PHP_EOL; |
|
| 431 | } |
||
| 432 | |||
| 433 | /** |
||
| 434 | * |
||
| 435 | * Adds a JOIN table and columns to the query. |
||
| 436 | * |
||
| 437 | * @param string $join The join type: inner, left, natural, etc. |
||
| 438 | * |
||
| 439 | * @param string $spec The table specification; "foo" or "foo AS bar". |
||
| 440 | * |
||
| 441 | * @param string $cond Join on this condition. |
||
| 442 | * |
||
| 443 | * @param array $bind Values to bind to ?-placeholders in the condition. |
||
| 444 | * |
||
| 445 | * @return $this |
||
| 446 | * |
||
| 447 | * @throws Exception |
||
| 448 | * |
||
| 449 | */ |
||
| 450 | 40 | 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 | 45 | 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 | 15 | public function joinSubSelect($join, $spec, $name, $cond = null, array $bind = array()) |
|
| 575 | |||
| 576 | /** |
||
| 577 | * |
||
| 578 | * Adds grouping to the query. |
||
| 579 | * |
||
| 580 | * @param array $spec The column(s) to group by. |
||
| 581 | * |
||
| 582 | * @return $this |
||
| 583 | * |
||
| 584 | */ |
||
| 585 | 5 | public function groupBy(array $spec) |
|
| 586 | { |
||
| 587 | 5 | foreach ($spec as $col) { |
|
| 588 | 5 | $this->group_by[] = $this->quoter->quoteNamesIn($col); |
|
| 589 | } |
||
| 590 | 5 | return $this; |
|
| 591 | } |
||
| 592 | |||
| 593 | /** |
||
| 594 | * |
||
| 595 | * Adds a HAVING condition to the query by AND. If the condition has |
||
| 596 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 597 | * those placeholders sequentially. |
||
| 598 | * |
||
| 599 | * @param string $cond The HAVING condition. |
||
| 600 | * |
||
| 601 | * @return $this |
||
| 602 | * |
||
| 603 | */ |
||
| 604 | 10 | public function having($cond) |
|
| 609 | |||
| 610 | /** |
||
| 611 | * |
||
| 612 | * Adds a HAVING condition to the query by AND. If the condition has |
||
| 613 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 614 | * those placeholders sequentially. |
||
| 615 | * |
||
| 616 | * @param string $cond The HAVING condition. |
||
| 617 | * |
||
| 618 | * @return $this |
||
| 619 | * |
||
| 620 | * @see having() |
||
| 621 | * |
||
| 622 | */ |
||
| 623 | 5 | public function orHaving($cond) |
|
| 628 | |||
| 629 | /** |
||
| 630 | * |
||
| 631 | * Sets the limit and count by page number. |
||
| 632 | * |
||
| 633 | * @param int $page Limit results to this page number. |
||
| 634 | * |
||
| 635 | * @return $this |
||
| 636 | * |
||
| 637 | */ |
||
| 638 | 25 | public function page($page) |
|
| 644 | |||
| 645 | /** |
||
| 646 | * |
||
| 647 | * Updates the limit and offset values when changing pagination. |
||
| 648 | * |
||
| 649 | * @return null |
||
| 650 | * |
||
| 651 | */ |
||
| 652 | 25 | protected function setPagingLimitOffset() |
|
| 653 | { |
||
| 654 | 25 | $this->limit = 0; |
|
| 655 | 25 | $this->offset = 0; |
|
| 656 | 25 | if ($this->page) { |
|
| 657 | 10 | $this->limit = $this->paging; |
|
| 658 | 10 | $this->offset = $this->paging * ($this->page - 1); |
|
| 659 | } |
||
| 660 | 25 | } |
|
| 661 | |||
| 662 | /** |
||
| 663 | * |
||
| 664 | * Returns the page number being selected. |
||
| 665 | * |
||
| 666 | * @return int |
||
| 667 | * |
||
| 668 | */ |
||
| 669 | 5 | public function getPage() |
|
| 673 | |||
| 674 | /** |
||
| 675 | * |
||
| 676 | * Takes the current select properties and retains them, then sets |
||
| 677 | * UNION for the next set of properties. |
||
| 678 | * |
||
| 679 | * @return $this |
||
| 680 | * |
||
| 681 | */ |
||
| 682 | 10 | public function union() |
|
| 688 | |||
| 689 | /** |
||
| 690 | * |
||
| 691 | * Takes the current select properties and retains them, then sets |
||
| 692 | * UNION ALL for the next set of properties. |
||
| 693 | * |
||
| 694 | * @return $this |
||
| 695 | * |
||
| 696 | */ |
||
| 697 | 5 | public function unionAll() |
|
| 703 | |||
| 704 | /** |
||
| 705 | * |
||
| 706 | * Returns the LIMIT value. |
||
| 707 | * |
||
| 708 | * @return int |
||
| 709 | * |
||
| 710 | */ |
||
| 711 | 10 | public function getLimit() |
|
| 715 | |||
| 716 | /** |
||
| 717 | * |
||
| 718 | * Returns the OFFSET value. |
||
| 719 | * |
||
| 720 | * @return int |
||
| 721 | * |
||
| 722 | */ |
||
| 723 | 10 | public function getOffset() |
|
| 727 | |||
| 728 | /** |
||
| 729 | * |
||
| 730 | * Clears the current select properties; generally used after adding a |
||
| 731 | * union. |
||
| 732 | * |
||
| 733 | * @return null |
||
| 734 | * |
||
| 735 | */ |
||
| 736 | 15 | protected function reset() |
|
| 750 | |||
| 751 | 15 | public function resetCols() |
|
| 756 | |||
| 757 | 15 | public function resetTables() |
|
| 764 | |||
| 765 | 15 | public function resetWhere() |
|
| 770 | |||
| 771 | 15 | public function resetGroupBy() |
|
| 776 | |||
| 777 | 15 | public function resetHaving() |
|
| 782 | |||
| 783 | 15 | public function resetOrderBy() |
|
| 788 | |||
| 789 | public function resetUnions() |
||
| 794 | |||
| 795 | /** |
||
| 796 | * |
||
| 797 | * Builds this query object into a string. |
||
| 798 | * |
||
| 799 | * @return string |
||
| 800 | * |
||
| 801 | */ |
||
| 802 | 174 | protected function build() |
|
| 815 | |||
| 816 | /** |
||
| 817 | * |
||
| 818 | * Builds the columns clause. |
||
| 819 | * |
||
| 820 | * @return string |
||
| 821 | * |
||
| 822 | * @throws Exception when there are no columns in the SELECT. |
||
| 823 | * |
||
| 824 | */ |
||
| 825 | 174 | protected function buildCols() |
|
| 826 | { |
||
| 827 | 174 | if (! $this->cols) { |
|
| 828 | 5 | throw new Exception('No columns in the SELECT.'); |
|
| 829 | } |
||
| 830 | |||
| 831 | 169 | $cols = array(); |
|
| 832 | 169 | foreach ($this->cols as $key => $val) { |
|
| 833 | 169 | if (is_int($key)) { |
|
| 834 | 169 | $cols[] = $this->quoter->quoteNamesIn($val); |
|
| 835 | } else { |
||
| 836 | 169 | $cols[] = $this->quoter->quoteNamesIn("$val AS $key"); |
|
| 837 | } |
||
| 838 | } |
||
| 839 | |||
| 840 | 169 | return $this->indentCsv($cols); |
|
| 841 | } |
||
| 842 | |||
| 843 | /** |
||
| 844 | * |
||
| 845 | * Builds the FROM clause. |
||
| 846 | * |
||
| 847 | * @return string |
||
| 848 | * |
||
| 849 | */ |
||
| 850 | 169 | protected function buildFrom() |
|
| 851 | { |
||
| 852 | 169 | if (! $this->from) { |
|
| 853 | 60 | return ''; // not applicable |
|
| 854 | } |
||
| 855 | |||
| 856 | 109 | $refs = array(); |
|
| 857 | 109 | foreach ($this->from as $from) { |
|
| 858 | 109 | $refs[] = implode(PHP_EOL, $from); |
|
| 859 | } |
||
| 860 | 109 | return PHP_EOL . 'FROM' . $this->indentCsv($refs); |
|
| 861 | } |
||
| 862 | |||
| 863 | /** |
||
| 864 | * |
||
| 865 | * Builds the GROUP BY clause. |
||
| 866 | * |
||
| 867 | * @return string |
||
| 868 | * |
||
| 869 | */ |
||
| 870 | 169 | protected function buildGroupBy() |
|
| 878 | |||
| 879 | /** |
||
| 880 | * |
||
| 881 | * Builds the HAVING clause. |
||
| 882 | * |
||
| 883 | * @return string |
||
| 884 | * |
||
| 885 | */ |
||
| 886 | 169 | protected function buildHaving() |
|
| 894 | |||
| 895 | /** |
||
| 896 | * |
||
| 897 | * Builds the FOR UPDATE clause. |
||
| 898 | * |
||
| 899 | * @return string |
||
| 900 | * |
||
| 901 | */ |
||
| 902 | 169 | protected function buildForUpdate() |
|
| 910 | |||
| 911 | /** |
||
| 912 | * |
||
| 913 | * Adds a WHERE condition to the query by AND. If the condition has |
||
| 914 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 915 | * those placeholders sequentially. |
||
| 916 | * |
||
| 917 | * @param string $cond The WHERE condition. |
||
| 918 | * @param mixed ...$bind arguments to bind to placeholders |
||
| 919 | * |
||
| 920 | * @return $this |
||
| 921 | * |
||
| 922 | */ |
||
| 923 | 30 | public function where($cond) |
|
| 928 | |||
| 929 | /** |
||
| 930 | * |
||
| 931 | * Adds a WHERE condition to the query by OR. If the condition has |
||
| 932 | * ?-placeholders, additional arguments to the method will be bound to |
||
| 933 | * those placeholders sequentially. |
||
| 934 | * |
||
| 935 | * @param string $cond The WHERE condition. |
||
| 936 | * @param mixed ...$bind arguments to bind to placeholders |
||
| 937 | * |
||
| 938 | * @return $this |
||
| 939 | * |
||
| 940 | * @see where() |
||
| 941 | * |
||
| 942 | */ |
||
| 943 | 5 | public function orWhere($cond) |
|
| 948 | |||
| 949 | /** |
||
| 950 | * |
||
| 951 | * Sets a limit count on the query. |
||
| 952 | * |
||
| 953 | * @param int $limit The number of rows to select. |
||
| 954 | * |
||
| 955 | * @return $this |
||
| 956 | * |
||
| 957 | */ |
||
| 958 | 30 | public function limit($limit) |
|
| 959 | { |
||
| 960 | 30 | $this->limit = (int) $limit; |
|
| 961 | 30 | if ($this->page) { |
|
| 962 | 5 | $this->page = 0; |
|
| 963 | 5 | $this->offset = 0; |
|
| 964 | } |
||
| 965 | 30 | return $this; |
|
| 966 | } |
||
| 967 | |||
| 968 | /** |
||
| 969 | * |
||
| 970 | * Sets a limit offset on the query. |
||
| 971 | * |
||
| 972 | * @param int $offset Start returning after this many rows. |
||
| 973 | * |
||
| 974 | * @return $this |
||
| 975 | * |
||
| 976 | */ |
||
| 977 | 30 | public function offset($offset) |
|
| 978 | { |
||
| 979 | 30 | $this->offset = (int) $offset; |
|
| 980 | 30 | if ($this->page) { |
|
| 981 | 5 | $this->page = 0; |
|
| 982 | 5 | $this->limit = 0; |
|
| 983 | } |
||
| 984 | 30 | return $this; |
|
| 985 | } |
||
| 986 | |||
| 987 | /** |
||
| 988 | * |
||
| 989 | * Adds a column order to the query. |
||
| 990 | * |
||
| 991 | * @param array $spec The columns and direction to order by. |
||
| 992 | * |
||
| 993 | * @return $this |
||
| 994 | * |
||
| 995 | */ |
||
| 996 | 5 | public function orderBy(array $spec) |
|
| 1000 | } |
||
| 1001 |
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.