Complex classes like Query 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 Query, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
46 | class Query extends Component implements QueryInterface |
||
47 | { |
||
48 | use QueryTrait; |
||
49 | |||
50 | /** |
||
51 | * @var array the columns being selected. For example, `['id', 'name']`. |
||
52 | * This is used to construct the SELECT clause in a SQL statement. If not set, it means selecting all columns. |
||
53 | * @see select() |
||
54 | */ |
||
55 | public $select; |
||
56 | /** |
||
57 | * @var string additional option that should be appended to the 'SELECT' keyword. For example, |
||
58 | * in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used. |
||
59 | */ |
||
60 | public $selectOption; |
||
61 | /** |
||
62 | * @var bool whether to select distinct rows of data only. If this is set true, |
||
63 | * the SELECT clause would be changed to SELECT DISTINCT. |
||
64 | */ |
||
65 | public $distinct; |
||
66 | /** |
||
67 | * @var array the table(s) to be selected from. For example, `['user', 'post']`. |
||
68 | * This is used to construct the FROM clause in a SQL statement. |
||
69 | * @see from() |
||
70 | */ |
||
71 | public $from; |
||
72 | /** |
||
73 | * @var array how to group the query results. For example, `['company', 'department']`. |
||
74 | * This is used to construct the GROUP BY clause in a SQL statement. |
||
75 | */ |
||
76 | public $groupBy; |
||
77 | /** |
||
78 | * @var array how to join with other tables. Each array element represents the specification |
||
79 | * of one join which has the following structure: |
||
80 | * |
||
81 | * ```php |
||
82 | * [$joinType, $tableName, $joinCondition] |
||
83 | * ``` |
||
84 | * |
||
85 | * For example, |
||
86 | * |
||
87 | * ```php |
||
88 | * [ |
||
89 | * ['INNER JOIN', 'user', 'user.id = author_id'], |
||
90 | * ['LEFT JOIN', 'team', 'team.id = team_id'], |
||
91 | * ] |
||
92 | * ``` |
||
93 | */ |
||
94 | public $join; |
||
95 | /** |
||
96 | * @var string|array|Expression the condition to be applied in the GROUP BY clause. |
||
97 | * It can be either a string or an array. Please refer to [[where()]] on how to specify the condition. |
||
98 | */ |
||
99 | public $having; |
||
100 | /** |
||
101 | * @var array this is used to construct the UNION clause(s) in a SQL statement. |
||
102 | * Each array element is an array of the following structure: |
||
103 | * |
||
104 | * - `query`: either a string or a [[Query]] object representing a query |
||
105 | * - `all`: boolean, whether it should be `UNION ALL` or `UNION` |
||
106 | */ |
||
107 | public $union; |
||
108 | /** |
||
109 | * @var array list of query parameter values indexed by parameter placeholders. |
||
110 | * For example, `[':name' => 'Dan', ':age' => 31]`. |
||
111 | */ |
||
112 | public $params = []; |
||
113 | |||
114 | |||
115 | /** |
||
116 | * Creates a DB command that can be used to execute this query. |
||
117 | * @param Connection $db the database connection used to generate the SQL statement. |
||
118 | * If this parameter is not given, the `db` application component will be used. |
||
119 | * @return Command the created DB command instance. |
||
120 | */ |
||
121 | 161 | public function createCommand($db = null) |
|
130 | |||
131 | /** |
||
132 | * Prepares for building SQL. |
||
133 | * This method is called by [[QueryBuilder]] when it starts to build SQL from a query object. |
||
134 | * You may override this method to do some final preparation work when converting a query into a SQL statement. |
||
135 | * @param QueryBuilder $builder |
||
136 | * @return $this a prepared query instance which will be used by [[QueryBuilder]] to build the SQL |
||
137 | */ |
||
138 | 465 | public function prepare($builder) |
|
142 | |||
143 | /** |
||
144 | * Starts a batch query. |
||
145 | * |
||
146 | * A batch query supports fetching data in batches, which can keep the memory usage under a limit. |
||
147 | * This method will return a [[BatchQueryResult]] object which implements the [[\Iterator]] interface |
||
148 | * and can be traversed to retrieve the data in batches. |
||
149 | * |
||
150 | * For example, |
||
151 | * |
||
152 | * ```php |
||
153 | * $query = (new Query)->from('user'); |
||
154 | * foreach ($query->batch() as $rows) { |
||
155 | * // $rows is an array of 100 or fewer rows from user table |
||
156 | * } |
||
157 | * ``` |
||
158 | * |
||
159 | * @param int $batchSize the number of records to be fetched in each batch. |
||
160 | * @param Connection $db the database connection. If not set, the "db" application component will be used. |
||
161 | * @return BatchQueryResult the batch query result. It implements the [[\Iterator]] interface |
||
162 | * and can be traversed to retrieve the data in batches. |
||
163 | */ |
||
164 | 6 | public function batch($batchSize = 100, $db = null) |
|
174 | |||
175 | /** |
||
176 | * Starts a batch query and retrieves data row by row. |
||
177 | * This method is similar to [[batch()]] except that in each iteration of the result, |
||
178 | * only one row of data is returned. For example, |
||
179 | * |
||
180 | * ```php |
||
181 | * $query = (new Query)->from('user'); |
||
182 | * foreach ($query->each() as $row) { |
||
183 | * } |
||
184 | * ``` |
||
185 | * |
||
186 | * @param int $batchSize the number of records to be fetched in each batch. |
||
187 | * @param Connection $db the database connection. If not set, the "db" application component will be used. |
||
188 | * @return BatchQueryResult the batch query result. It implements the [[\Iterator]] interface |
||
189 | * and can be traversed to retrieve the data in batches. |
||
190 | */ |
||
191 | 3 | public function each($batchSize = 100, $db = null) |
|
201 | |||
202 | /** |
||
203 | * Executes the query and returns all results as an array. |
||
204 | * @param Connection $db the database connection used to generate the SQL statement. |
||
205 | * If this parameter is not given, the `db` application component will be used. |
||
206 | * @return array the query results. If the query results in nothing, an empty array will be returned. |
||
207 | */ |
||
208 | 274 | public function all($db = null) |
|
216 | |||
217 | /** |
||
218 | * Converts the raw query results into the format as specified by this query. |
||
219 | * This method is internally used to convert the data fetched from database |
||
220 | * into the format as required by this query. |
||
221 | * @param array $rows the raw query result from database |
||
222 | * @return array the converted query result |
||
223 | */ |
||
224 | 107 | public function populate($rows) |
|
240 | |||
241 | /** |
||
242 | * Executes the query and returns a single row of result. |
||
243 | * @param Connection $db the database connection used to generate the SQL statement. |
||
244 | * If this parameter is not given, the `db` application component will be used. |
||
245 | * @return array|bool the first row (in terms of an array) of the query result. False is returned if the query |
||
246 | * results in nothing. |
||
247 | */ |
||
248 | 297 | public function one($db = null) |
|
255 | |||
256 | /** |
||
257 | * Returns the query result as a scalar value. |
||
258 | * The value returned will be the first column in the first row of the query results. |
||
259 | * @param Connection $db the database connection used to generate the SQL statement. |
||
260 | * If this parameter is not given, the `db` application component will be used. |
||
261 | * @return string|null|false the value of the first column in the first row of the query result. |
||
262 | * False is returned if the query result is empty. |
||
263 | */ |
||
264 | 14 | public function scalar($db = null) |
|
271 | |||
272 | /** |
||
273 | * Executes the query and returns the first column of the result. |
||
274 | * @param Connection $db the database connection used to generate the SQL statement. |
||
275 | * If this parameter is not given, the `db` application component will be used. |
||
276 | * @return array the first column of the query result. An empty array is returned if the query results in nothing. |
||
277 | */ |
||
278 | 24 | public function column($db = null) |
|
304 | |||
305 | /** |
||
306 | * Returns the number of records. |
||
307 | * @param string $q the COUNT expression. Defaults to '*'. |
||
308 | * Make sure you properly [quote](guide:db-dao#quoting-table-and-column-names) column names in the expression. |
||
309 | * @param Connection $db the database connection used to generate the SQL statement. |
||
310 | * If this parameter is not given (or null), the `db` application component will be used. |
||
311 | * @return int|string number of records. The result may be a string depending on the |
||
312 | * underlying database engine and to support integer values higher than a 32bit PHP integer can handle. |
||
313 | */ |
||
314 | 72 | public function count($q = '*', $db = null) |
|
321 | |||
322 | /** |
||
323 | * Returns the sum of the specified column values. |
||
324 | * @param string $q the column name or expression. |
||
325 | * Make sure you properly [quote](guide:db-dao#quoting-table-and-column-names) column names in the expression. |
||
326 | * @param Connection $db the database connection used to generate the SQL statement. |
||
327 | * If this parameter is not given, the `db` application component will be used. |
||
328 | * @return mixed the sum of the specified column values. |
||
329 | */ |
||
330 | 9 | public function sum($q, $db = null) |
|
337 | |||
338 | /** |
||
339 | * Returns the average of the specified column values. |
||
340 | * @param string $q the column name or expression. |
||
341 | * Make sure you properly [quote](guide:db-dao#quoting-table-and-column-names) column names in the expression. |
||
342 | * @param Connection $db the database connection used to generate the SQL statement. |
||
343 | * If this parameter is not given, the `db` application component will be used. |
||
344 | * @return mixed the average of the specified column values. |
||
345 | */ |
||
346 | 9 | public function average($q, $db = null) |
|
353 | |||
354 | /** |
||
355 | * Returns the minimum of the specified column values. |
||
356 | * @param string $q the column name or expression. |
||
357 | * Make sure you properly [quote](guide:db-dao#quoting-table-and-column-names) column names in the expression. |
||
358 | * @param Connection $db the database connection used to generate the SQL statement. |
||
359 | * If this parameter is not given, the `db` application component will be used. |
||
360 | * @return mixed the minimum of the specified column values. |
||
361 | */ |
||
362 | 9 | public function min($q, $db = null) |
|
366 | |||
367 | /** |
||
368 | * Returns the maximum of the specified column values. |
||
369 | * @param string $q the column name or expression. |
||
370 | * Make sure you properly [quote](guide:db-dao#quoting-table-and-column-names) column names in the expression. |
||
371 | * @param Connection $db the database connection used to generate the SQL statement. |
||
372 | * If this parameter is not given, the `db` application component will be used. |
||
373 | * @return mixed the maximum of the specified column values. |
||
374 | */ |
||
375 | 9 | public function max($q, $db = null) |
|
379 | |||
380 | /** |
||
381 | * Returns a value indicating whether the query result contains any row of data. |
||
382 | * @param Connection $db the database connection used to generate the SQL statement. |
||
383 | * If this parameter is not given, the `db` application component will be used. |
||
384 | * @return bool whether the query result contains any row of data. |
||
385 | */ |
||
386 | 57 | public function exists($db = null) |
|
397 | |||
398 | /** |
||
399 | * Queries a scalar value by setting [[select]] first. |
||
400 | * Restores the value of select to make this query reusable. |
||
401 | * @param string|Expression $selectExpression |
||
402 | * @param Connection|null $db |
||
403 | * @return bool|string |
||
404 | */ |
||
405 | 72 | protected function queryScalar($selectExpression, $db) |
|
433 | |||
434 | /** |
||
435 | * Sets the SELECT part of the query. |
||
436 | * @param string|array|Expression $columns the columns to be selected. |
||
437 | * Columns can be specified in either a string (e.g. "id, name") or an array (e.g. ['id', 'name']). |
||
438 | * Columns can be prefixed with table names (e.g. "user.id") and/or contain column aliases (e.g. "user.id AS user_id"). |
||
439 | * The method will automatically quote the column names unless a column contains some parenthesis |
||
440 | * (which means the column contains a DB expression). A DB expression may also be passed in form of |
||
441 | * an [[Expression]] object. |
||
442 | * |
||
443 | * Note that if you are selecting an expression like `CONCAT(first_name, ' ', last_name)`, you should |
||
444 | * use an array to specify the columns. Otherwise, the expression may be incorrectly split into several parts. |
||
445 | * |
||
446 | * When the columns are specified as an array, you may also use array keys as the column aliases (if a column |
||
447 | * does not need alias, do not use a string key). |
||
448 | * |
||
449 | * Starting from version 2.0.1, you may also select sub-queries as columns by specifying each such column |
||
450 | * as a `Query` instance representing the sub-query. |
||
451 | * |
||
452 | * @param string $option additional option that should be appended to the 'SELECT' keyword. For example, |
||
453 | * in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used. |
||
454 | * @return $this the query object itself |
||
455 | */ |
||
456 | 209 | public function select($columns, $option = null) |
|
467 | |||
468 | /** |
||
469 | * Add more columns to the SELECT part of the query. |
||
470 | * |
||
471 | * Note, that if [[select]] has not been specified before, you should include `*` explicitly |
||
472 | * if you want to select all remaining columns too: |
||
473 | * |
||
474 | * ```php |
||
475 | * $query->addSelect(["*", "CONCAT(first_name, ' ', last_name) AS full_name"])->one(); |
||
476 | * ``` |
||
477 | * |
||
478 | * @param string|array|Expression $columns the columns to add to the select. See [[select()]] for more |
||
479 | * details about the format of this parameter. |
||
480 | * @return $this the query object itself |
||
481 | * @see select() |
||
482 | */ |
||
483 | 9 | public function addSelect($columns) |
|
497 | |||
498 | /** |
||
499 | * Sets the value indicating whether to SELECT DISTINCT or not. |
||
500 | * @param bool $value whether to SELECT DISTINCT or not. |
||
501 | * @return $this the query object itself |
||
502 | */ |
||
503 | 6 | public function distinct($value = true) |
|
508 | |||
509 | /** |
||
510 | * Sets the FROM part of the query. |
||
511 | * @param string|array $tables the table(s) to be selected from. This can be either a string (e.g. `'user'`) |
||
512 | * or an array (e.g. `['user', 'profile']`) specifying one or several table names. |
||
513 | * Table names can contain schema prefixes (e.g. `'public.user'`) and/or table aliases (e.g. `'user u'`). |
||
514 | * The method will automatically quote the table names unless it contains some parenthesis |
||
515 | * (which means the table is given as a sub-query or DB expression). |
||
516 | * |
||
517 | * When the tables are specified as an array, you may also use the array keys as the table aliases |
||
518 | * (if a table does not need alias, do not use a string key). |
||
519 | * |
||
520 | * Use a Query object to represent a sub-query. In this case, the corresponding array key will be used |
||
521 | * as the alias for the sub-query. |
||
522 | * |
||
523 | * Here are some examples: |
||
524 | * |
||
525 | * ```php |
||
526 | * // SELECT * FROM `user` `u`, `profile`; |
||
527 | * $query = (new \yii\db\Query)->from(['u' => 'user', 'profile']); |
||
528 | * |
||
529 | * // SELECT * FROM (SELECT * FROM `user` WHERE `active` = 1) `activeusers`; |
||
530 | * $subquery = (new \yii\db\Query)->from('user')->where(['active' => true]) |
||
531 | * $query = (new \yii\db\Query)->from(['activeusers' => $subquery]); |
||
532 | * |
||
533 | * // subquery can also be a string with plain SQL wrapped in parenthesis |
||
534 | * // SELECT * FROM (SELECT * FROM `user` WHERE `active` = 1) `activeusers`; |
||
535 | * $subquery = "(SELECT * FROM `user` WHERE `active` = 1)"; |
||
536 | * $query = (new \yii\db\Query)->from(['activeusers' => $subquery]); |
||
537 | * ``` |
||
538 | * |
||
539 | * @return $this the query object itself |
||
540 | */ |
||
541 | 209 | public function from($tables) |
|
549 | |||
550 | /** |
||
551 | * Sets the WHERE part of the query. |
||
552 | * |
||
553 | * The method requires a `$condition` parameter, and optionally a `$params` parameter |
||
554 | * specifying the values to be bound to the query. |
||
555 | * |
||
556 | * The `$condition` parameter should be either a string (e.g. `'id=1'`) or an array. |
||
557 | * |
||
558 | * @inheritdoc |
||
559 | * |
||
560 | * @param string|array|Expression $condition the conditions that should be put in the WHERE part. |
||
561 | * @param array $params the parameters (name => value) to be bound to the query. |
||
562 | * @return $this the query object itself |
||
563 | * @see andWhere() |
||
564 | * @see orWhere() |
||
565 | * @see QueryInterface::where() |
||
566 | */ |
||
567 | 461 | public function where($condition, $params = []) |
|
573 | |||
574 | /** |
||
575 | * Adds an additional WHERE condition to the existing one. |
||
576 | * The new condition and the existing one will be joined using the 'AND' operator. |
||
577 | * @param string|array|Expression $condition the new WHERE condition. Please refer to [[where()]] |
||
578 | * on how to specify this parameter. |
||
579 | * @param array $params the parameters (name => value) to be bound to the query. |
||
580 | * @return $this the query object itself |
||
581 | * @see where() |
||
582 | * @see orWhere() |
||
583 | */ |
||
584 | 254 | public function andWhere($condition, $params = []) |
|
594 | |||
595 | /** |
||
596 | * Adds an additional WHERE condition to the existing one. |
||
597 | * The new condition and the existing one will be joined using the 'OR' operator. |
||
598 | * @param string|array|Expression $condition the new WHERE condition. Please refer to [[where()]] |
||
599 | * on how to specify this parameter. |
||
600 | * @param array $params the parameters (name => value) to be bound to the query. |
||
601 | * @return $this the query object itself |
||
602 | * @see where() |
||
603 | * @see andWhere() |
||
604 | */ |
||
605 | 3 | public function orWhere($condition, $params = []) |
|
615 | |||
616 | /** |
||
617 | * Adds a filtering condition for a specific column and allow the user to choose a filter operator. |
||
618 | * |
||
619 | * It adds an additional WHERE condition for the given field and determines the comparison operator |
||
620 | * based on the first few characters of the given value. |
||
621 | * The condition is added in the same way as in [[andFilterWhere]] so [[isEmpty()|empty values]] are ignored. |
||
622 | * The new condition and the existing one will be joined using the 'AND' operator. |
||
623 | * |
||
624 | * The comparison operator is intelligently determined based on the first few characters in the given value. |
||
625 | * In particular, it recognizes the following operators if they appear as the leading characters in the given value: |
||
626 | * |
||
627 | * - `<`: the column must be less than the given value. |
||
628 | * - `>`: the column must be greater than the given value. |
||
629 | * - `<=`: the column must be less than or equal to the given value. |
||
630 | * - `>=`: the column must be greater than or equal to the given value. |
||
631 | * - `<>`: the column must not be the same as the given value. |
||
632 | * - `=`: the column must be equal to the given value. |
||
633 | * - If none of the above operators is detected, the `$defaultOperator` will be used. |
||
634 | * |
||
635 | * @param string $name the column name. |
||
636 | * @param string $value the column value optionally prepended with the comparison operator. |
||
637 | * @param string $defaultOperator The operator to use, when no operator is given in `$value`. |
||
638 | * Defaults to `=`, performing an exact match. |
||
639 | * @return $this The query object itself |
||
640 | * @since 2.0.8 |
||
641 | */ |
||
642 | 3 | public function andFilterCompare($name, $value, $defaultOperator = '=') |
|
652 | |||
653 | /** |
||
654 | * Appends a JOIN part to the query. |
||
655 | * The first parameter specifies what type of join it is. |
||
656 | * @param string $type the type of join, such as INNER JOIN, LEFT JOIN. |
||
657 | * @param string|array $table the table to be joined. |
||
658 | * |
||
659 | * Use a string to represent the name of the table to be joined. |
||
660 | * The table name can contain a schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u'). |
||
661 | * The method will automatically quote the table name unless it contains some parenthesis |
||
662 | * (which means the table is given as a sub-query or DB expression). |
||
663 | * |
||
664 | * Use an array to represent joining with a sub-query. The array must contain only one element. |
||
665 | * The value must be a [[Query]] object representing the sub-query while the corresponding key |
||
666 | * represents the alias for the sub-query. |
||
667 | * |
||
668 | * @param string|array $on the join condition that should appear in the ON part. |
||
669 | * Please refer to [[where()]] on how to specify this parameter. |
||
670 | * |
||
671 | * Note that the array format of [[where()]] is designed to match columns to values instead of columns to columns, so |
||
672 | * the following would **not** work as expected: `['post.author_id' => 'user.id']`, it would |
||
673 | * match the `post.author_id` column value against the string `'user.id'`. |
||
674 | * It is recommended to use the string syntax here which is more suited for a join: |
||
675 | * |
||
676 | * ```php |
||
677 | * 'post.author_id = user.id' |
||
678 | * ``` |
||
679 | * |
||
680 | * @param array $params the parameters (name => value) to be bound to the query. |
||
681 | * @return $this the query object itself |
||
682 | */ |
||
683 | 36 | public function join($type, $table, $on = '', $params = []) |
|
688 | |||
689 | /** |
||
690 | * Appends an INNER JOIN part to the query. |
||
691 | * @param string|array $table the table to be joined. |
||
692 | * |
||
693 | * Use a string to represent the name of the table to be joined. |
||
694 | * The table name can contain a schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u'). |
||
695 | * The method will automatically quote the table name unless it contains some parenthesis |
||
696 | * (which means the table is given as a sub-query or DB expression). |
||
697 | * |
||
698 | * Use an array to represent joining with a sub-query. The array must contain only one element. |
||
699 | * The value must be a [[Query]] object representing the sub-query while the corresponding key |
||
700 | * represents the alias for the sub-query. |
||
701 | * |
||
702 | * @param string|array $on the join condition that should appear in the ON part. |
||
703 | * Please refer to [[join()]] on how to specify this parameter. |
||
704 | * @param array $params the parameters (name => value) to be bound to the query. |
||
705 | * @return $this the query object itself |
||
706 | */ |
||
707 | public function innerJoin($table, $on = '', $params = []) |
||
712 | |||
713 | /** |
||
714 | * Appends a LEFT OUTER JOIN part to the query. |
||
715 | * @param string|array $table the table to be joined. |
||
716 | * |
||
717 | * Use a string to represent the name of the table to be joined. |
||
718 | * The table name can contain a schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u'). |
||
719 | * The method will automatically quote the table name unless it contains some parenthesis |
||
720 | * (which means the table is given as a sub-query or DB expression). |
||
721 | * |
||
722 | * Use an array to represent joining with a sub-query. The array must contain only one element. |
||
723 | * The value must be a [[Query]] object representing the sub-query while the corresponding key |
||
724 | * represents the alias for the sub-query. |
||
725 | * |
||
726 | * @param string|array $on the join condition that should appear in the ON part. |
||
727 | * Please refer to [[join()]] on how to specify this parameter. |
||
728 | * @param array $params the parameters (name => value) to be bound to the query |
||
729 | * @return $this the query object itself |
||
730 | */ |
||
731 | 3 | public function leftJoin($table, $on = '', $params = []) |
|
736 | |||
737 | /** |
||
738 | * Appends a RIGHT OUTER JOIN part to the query. |
||
739 | * @param string|array $table the table to be joined. |
||
740 | * |
||
741 | * Use a string to represent the name of the table to be joined. |
||
742 | * The table name can contain a schema prefix (e.g. 'public.user') and/or table alias (e.g. 'user u'). |
||
743 | * The method will automatically quote the table name unless it contains some parenthesis |
||
744 | * (which means the table is given as a sub-query or DB expression). |
||
745 | * |
||
746 | * Use an array to represent joining with a sub-query. The array must contain only one element. |
||
747 | * The value must be a [[Query]] object representing the sub-query while the corresponding key |
||
748 | * represents the alias for the sub-query. |
||
749 | * |
||
750 | * @param string|array $on the join condition that should appear in the ON part. |
||
751 | * Please refer to [[join()]] on how to specify this parameter. |
||
752 | * @param array $params the parameters (name => value) to be bound to the query |
||
753 | * @return $this the query object itself |
||
754 | */ |
||
755 | public function rightJoin($table, $on = '', $params = []) |
||
760 | |||
761 | /** |
||
762 | * Sets the GROUP BY part of the query. |
||
763 | * @param string|array|Expression $columns the columns to be grouped by. |
||
764 | * Columns can be specified in either a string (e.g. "id, name") or an array (e.g. ['id', 'name']). |
||
765 | * The method will automatically quote the column names unless a column contains some parenthesis |
||
766 | * (which means the column contains a DB expression). |
||
767 | * |
||
768 | * Note that if your group-by is an expression containing commas, you should always use an array |
||
769 | * to represent the group-by information. Otherwise, the method will not be able to correctly determine |
||
770 | * the group-by columns. |
||
771 | * |
||
772 | * Since version 2.0.7, an [[Expression]] object can be passed to specify the GROUP BY part explicitly in plain SQL. |
||
773 | * @return $this the query object itself |
||
774 | * @see addGroupBy() |
||
775 | */ |
||
776 | 12 | public function groupBy($columns) |
|
786 | |||
787 | /** |
||
788 | * Adds additional group-by columns to the existing ones. |
||
789 | * @param string|array $columns additional columns to be grouped by. |
||
790 | * Columns can be specified in either a string (e.g. "id, name") or an array (e.g. ['id', 'name']). |
||
791 | * The method will automatically quote the column names unless a column contains some parenthesis |
||
792 | * (which means the column contains a DB expression). |
||
793 | * |
||
794 | * Note that if your group-by is an expression containing commas, you should always use an array |
||
795 | * to represent the group-by information. Otherwise, the method will not be able to correctly determine |
||
796 | * the group-by columns. |
||
797 | * |
||
798 | * Since version 2.0.7, an [[Expression]] object can be passed to specify the GROUP BY part explicitly in plain SQL. |
||
799 | * @return $this the query object itself |
||
800 | * @see groupBy() |
||
801 | */ |
||
802 | 3 | public function addGroupBy($columns) |
|
816 | |||
817 | /** |
||
818 | * Sets the HAVING part of the query. |
||
819 | * @param string|array|Expression $condition the conditions to be put after HAVING. |
||
820 | * Please refer to [[where()]] on how to specify this parameter. |
||
821 | * @param array $params the parameters (name => value) to be bound to the query. |
||
822 | * @return $this the query object itself |
||
823 | * @see andHaving() |
||
824 | * @see orHaving() |
||
825 | */ |
||
826 | 4 | public function having($condition, $params = []) |
|
832 | |||
833 | /** |
||
834 | * Adds an additional HAVING condition to the existing one. |
||
835 | * The new condition and the existing one will be joined using the 'AND' operator. |
||
836 | * @param string|array|Expression $condition the new HAVING condition. Please refer to [[where()]] |
||
837 | * on how to specify this parameter. |
||
838 | * @param array $params the parameters (name => value) to be bound to the query. |
||
839 | * @return $this the query object itself |
||
840 | * @see having() |
||
841 | * @see orHaving() |
||
842 | */ |
||
843 | 3 | public function andHaving($condition, $params = []) |
|
853 | |||
854 | /** |
||
855 | * Adds an additional HAVING condition to the existing one. |
||
856 | * The new condition and the existing one will be joined using the 'OR' operator. |
||
857 | * @param string|array|Expression $condition the new HAVING condition. Please refer to [[where()]] |
||
858 | * on how to specify this parameter. |
||
859 | * @param array $params the parameters (name => value) to be bound to the query. |
||
860 | * @return $this the query object itself |
||
861 | * @see having() |
||
862 | * @see andHaving() |
||
863 | */ |
||
864 | 3 | public function orHaving($condition, $params = []) |
|
874 | |||
875 | /** |
||
876 | * Appends a SQL statement using UNION operator. |
||
877 | * @param string|Query $sql the SQL statement to be appended using UNION |
||
878 | * @param bool $all TRUE if using UNION ALL and FALSE if using UNION |
||
879 | * @return $this the query object itself |
||
880 | */ |
||
881 | 10 | public function union($sql, $all = false) |
|
886 | |||
887 | /** |
||
888 | * Sets the parameters to be bound to the query. |
||
889 | * @param array $params list of query parameter values indexed by parameter placeholders. |
||
890 | * For example, `[':name' => 'Dan', ':age' => 31]`. |
||
891 | * @return $this the query object itself |
||
892 | * @see addParams() |
||
893 | */ |
||
894 | 6 | public function params($params) |
|
899 | |||
900 | /** |
||
901 | * Adds additional parameters to be bound to the query. |
||
902 | * @param array $params list of query parameter values indexed by parameter placeholders. |
||
903 | * For example, `[':name' => 'Dan', ':age' => 31]`. |
||
904 | * @return $this the query object itself |
||
905 | * @see params() |
||
906 | */ |
||
907 | 657 | public function addParams($params) |
|
924 | |||
925 | /** |
||
926 | * Creates a new Query object and copies its property values from an existing one. |
||
927 | * The properties being copies are the ones to be used by query builders. |
||
928 | * @param Query $from the source query object |
||
929 | * @return Query the new Query object |
||
930 | */ |
||
931 | 303 | public static function create($from) |
|
950 | } |
||
951 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.