Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
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 |
||
33 | class Query extends DatabaseQuery implements JsonSerializable, QueryInterface |
||
34 | { |
||
35 | |||
36 | use QueryTrait { |
||
37 | cache as private _cache; |
||
38 | all as private _all; |
||
39 | _decorateResults as private _applyDecorators; |
||
40 | __call as private _call; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Indicates that the operation should append to the list |
||
45 | * |
||
46 | * @var int |
||
47 | */ |
||
48 | const APPEND = 0; |
||
49 | |||
50 | /** |
||
51 | * Indicates that the operation should prepend to the list |
||
52 | * |
||
53 | * @var int |
||
54 | */ |
||
55 | const PREPEND = 1; |
||
56 | |||
57 | /** |
||
58 | * Indicates that the operation should overwrite the list |
||
59 | * |
||
60 | * @var bool |
||
61 | */ |
||
62 | const OVERWRITE = true; |
||
63 | |||
64 | /** |
||
65 | * Whether the user select any fields before being executed, this is used |
||
66 | * to determined if any fields should be automatically be selected. |
||
67 | * |
||
68 | * @var bool |
||
69 | */ |
||
70 | protected $_hasFields; |
||
71 | |||
72 | /** |
||
73 | * Tracks whether or not the original query should include |
||
74 | * fields from the top level table. |
||
75 | * |
||
76 | * @var bool |
||
77 | */ |
||
78 | protected $_autoFields; |
||
79 | |||
80 | /** |
||
81 | * Whether to hydrate results into entity objects |
||
82 | * |
||
83 | * @var bool |
||
84 | */ |
||
85 | protected $_hydrate = true; |
||
86 | |||
87 | /** |
||
88 | * A callable function that can be used to calculate the total amount of |
||
89 | * records this query will match when not using `limit` |
||
90 | * |
||
91 | * @var callable |
||
92 | */ |
||
93 | protected $_counter; |
||
94 | |||
95 | /** |
||
96 | * Instance of a class responsible for storing association containments and |
||
97 | * for eager loading them when this query is executed |
||
98 | * |
||
99 | * @var \Cake\ORM\EagerLoader |
||
100 | */ |
||
101 | protected $_eagerLoader; |
||
102 | |||
103 | /** |
||
104 | * True if the beforeFind event has already been triggered for this query |
||
105 | * |
||
106 | * @var bool |
||
107 | */ |
||
108 | protected $_beforeFindFired = false; |
||
109 | |||
110 | /** |
||
111 | * The COUNT(*) for the query. |
||
112 | * |
||
113 | * When set, count query execution will be bypassed. |
||
114 | * |
||
115 | * @var int |
||
116 | */ |
||
117 | protected $_resultsCount; |
||
118 | |||
119 | /** |
||
120 | * Constructor |
||
121 | * |
||
122 | * @param \Cake\Database\Connection $connection The connection object |
||
123 | * @param \Cake\ORM\Table $table The table this query is starting on |
||
124 | */ |
||
125 | public function __construct($connection, $table) |
||
134 | |||
135 | /** |
||
136 | * {@inheritDoc} |
||
137 | * |
||
138 | * If you pass an instance of a `Cake\ORM\Table` or `Cake\ORM\Association` class, |
||
139 | * all the fields in the schema of the table or the association will be added to |
||
140 | * the select clause. |
||
141 | * |
||
142 | * @param array|ExpressionInterface|string|\Cake\ORM\Table|\Cake\ORM\Association $fields fields |
||
143 | * to be added to the list. |
||
144 | * @param bool $overwrite whether to reset fields with passed list or not |
||
145 | */ |
||
146 | public function select($fields = [], $overwrite = false) |
||
158 | |||
159 | /** |
||
160 | * Hints this object to associate the correct types when casting conditions |
||
161 | * for the database. This is done by extracting the field types from the schema |
||
162 | * associated to the passed table object. This prevents the user from repeating |
||
163 | * himself when specifying conditions. |
||
164 | * |
||
165 | * This method returns the same query object for chaining. |
||
166 | * |
||
167 | * @param \Cake\ORM\Table $table The table to pull types from |
||
168 | * @return $this |
||
169 | */ |
||
170 | public function addDefaultTypes(Table $table) |
||
182 | |||
183 | /** |
||
184 | * Sets the instance of the eager loader class to use for loading associations |
||
185 | * and storing containments. If called with no arguments, it will return the |
||
186 | * currently configured instance. |
||
187 | * |
||
188 | * @param \Cake\ORM\EagerLoader $instance The eager loader to use. Pass null |
||
189 | * to get the current eagerloader. |
||
190 | * @return \Cake\ORM\EagerLoader|$this |
||
191 | */ |
||
192 | public function eagerLoader(EagerLoader $instance = null) |
||
203 | |||
204 | /** |
||
205 | * Sets the list of associations that should be eagerly loaded along with this |
||
206 | * query. The list of associated tables passed must have been previously set as |
||
207 | * associations using the Table API. |
||
208 | * |
||
209 | * ### Example: |
||
210 | * |
||
211 | * ``` |
||
212 | * // Bring articles' author information |
||
213 | * $query->contain('Author'); |
||
214 | * |
||
215 | * // Also bring the category and tags associated to each article |
||
216 | * $query->contain(['Category', 'Tag']); |
||
217 | * ``` |
||
218 | * |
||
219 | * Associations can be arbitrarily nested using dot notation or nested arrays, |
||
220 | * this allows this object to calculate joins or any additional queries that |
||
221 | * must be executed to bring the required associated data. |
||
222 | * |
||
223 | * ### Example: |
||
224 | * |
||
225 | * ``` |
||
226 | * // Eager load the product info, and for each product load other 2 associations |
||
227 | * $query->contain(['Product' => ['Manufacturer', 'Distributor']); |
||
228 | * |
||
229 | * // Which is equivalent to calling |
||
230 | * $query->contain(['Products.Manufactures', 'Products.Distributors']); |
||
231 | * |
||
232 | * // For an author query, load his region, state and country |
||
233 | * $query->contain('Regions.States.Countries'); |
||
234 | * ``` |
||
235 | * |
||
236 | * It is possible to control the conditions and fields selected for each of the |
||
237 | * contained associations: |
||
238 | * |
||
239 | * ### Example: |
||
240 | * |
||
241 | * ``` |
||
242 | * $query->contain(['Tags' => function ($q) { |
||
243 | * return $q->where(['Tags.is_popular' => true]); |
||
244 | * }]); |
||
245 | * |
||
246 | * $query->contain(['Products.Manufactures' => function ($q) { |
||
247 | * return $q->select(['name'])->where(['Manufactures.active' => true]); |
||
248 | * }]); |
||
249 | * ``` |
||
250 | * |
||
251 | * Each association might define special options when eager loaded, the allowed |
||
252 | * options that can be set per association are: |
||
253 | * |
||
254 | * - foreignKey: Used to set a different field to match both tables, if set to false |
||
255 | * no join conditions will be generated automatically. `false` can only be used on |
||
256 | * joinable associations and cannot be used with hasMany or belongsToMany associations. |
||
257 | * - fields: An array with the fields that should be fetched from the association |
||
258 | * - queryBuilder: Equivalent to passing a callable instead of an options array |
||
259 | * |
||
260 | * ### Example: |
||
261 | * |
||
262 | * ``` |
||
263 | * // Set options for the hasMany articles that will be eagerly loaded for an author |
||
264 | * $query->contain([ |
||
265 | * 'Articles' => [ |
||
266 | * 'fields' => ['title', 'author_id'] |
||
267 | * ] |
||
268 | * ]); |
||
269 | * ``` |
||
270 | * |
||
271 | * When containing associations, it is important to include foreign key columns. |
||
272 | * Failing to do so will trigger exceptions. |
||
273 | * |
||
274 | * ``` |
||
275 | * // Use special join conditions for getting an Articles's belongsTo 'authors' |
||
276 | * $query->contain([ |
||
277 | * 'Authors' => [ |
||
278 | * 'foreignKey' => false, |
||
279 | * 'queryBuilder' => function ($q) { |
||
280 | * return $q->where(...); // Add full filtering conditions |
||
281 | * } |
||
282 | * ] |
||
283 | * ]); |
||
284 | * ``` |
||
285 | * |
||
286 | * If called with no arguments, this function will return an array with |
||
287 | * with the list of previously configured associations to be contained in the |
||
288 | * result. |
||
289 | * |
||
290 | * If called with an empty first argument and $override is set to true, the |
||
291 | * previous list will be emptied. |
||
292 | * |
||
293 | * @param array|string $associations list of table aliases to be queried |
||
294 | * @param bool $override whether override previous list with the one passed |
||
295 | * defaults to merging previous list with the new one. |
||
296 | * @return array|$this |
||
297 | */ |
||
298 | public function contain($associations = null, $override = false) |
||
314 | |||
315 | /** |
||
316 | * Used to recursively add contained association column types to |
||
317 | * the query. |
||
318 | * |
||
319 | * @param \Cake\ORM\Table $table The table instance to pluck associations from. |
||
320 | * @param \Cake\Database\TypeMap $typeMap The typemap to check for columns in. |
||
321 | * This typemap is indirectly mutated via Cake\ORM\Query::addDefaultTypes() |
||
322 | * @param array $associations The nested tree of associations to walk. |
||
323 | * @return void |
||
324 | */ |
||
325 | protected function _addAssociationsToTypeMap($table, $typeMap, $associations) |
||
342 | |||
343 | /** |
||
344 | * Adds filtering conditions to this query to only bring rows that have a relation |
||
345 | * to another from an associated table, based on conditions in the associated table. |
||
346 | * |
||
347 | * This function will add entries in the `contain` graph. |
||
348 | * |
||
349 | * ### Example: |
||
350 | * |
||
351 | * ``` |
||
352 | * // Bring only articles that were tagged with 'cake' |
||
353 | * $query->matching('Tags', function ($q) { |
||
354 | * return $q->where(['name' => 'cake']); |
||
355 | * ); |
||
356 | * ``` |
||
357 | * |
||
358 | * It is possible to filter by deep associations by using dot notation: |
||
359 | * |
||
360 | * ### Example: |
||
361 | * |
||
362 | * ``` |
||
363 | * // Bring only articles that were commented by 'markstory' |
||
364 | * $query->matching('Comments.Users', function ($q) { |
||
365 | * return $q->where(['username' => 'markstory']); |
||
366 | * ); |
||
367 | * ``` |
||
368 | * |
||
369 | * As this function will create `INNER JOIN`, you might want to consider |
||
370 | * calling `distinct` on this query as you might get duplicate rows if |
||
371 | * your conditions don't filter them already. This might be the case, for example, |
||
372 | * of the same user commenting more than once in the same article. |
||
373 | * |
||
374 | * ### Example: |
||
375 | * |
||
376 | * ``` |
||
377 | * // Bring unique articles that were commented by 'markstory' |
||
378 | * $query->distinct(['Articles.id']) |
||
379 | * ->matching('Comments.Users', function ($q) { |
||
380 | * return $q->where(['username' => 'markstory']); |
||
381 | * ); |
||
382 | * ``` |
||
383 | * |
||
384 | * Please note that the query passed to the closure will only accept calling |
||
385 | * `select`, `where`, `andWhere` and `orWhere` on it. If you wish to |
||
386 | * add more complex clauses you can do it directly in the main query. |
||
387 | * |
||
388 | * @param string $assoc The association to filter by |
||
389 | * @param callable $builder a function that will receive a pre-made query object |
||
390 | * that can be used to add custom conditions or selecting some fields |
||
391 | * @return $this |
||
392 | */ |
||
393 | public function matching($assoc, callable $builder = null) |
||
399 | |||
400 | /** |
||
401 | * Creates a LEFT JOIN with the passed association table while preserving |
||
402 | * the foreign key matching and the custom conditions that were originally set |
||
403 | * for it. |
||
404 | * |
||
405 | * This function will add entries in the `contain` graph. |
||
406 | * |
||
407 | * ### Example: |
||
408 | * |
||
409 | * ``` |
||
410 | * // Get the count of articles per user |
||
411 | * $usersQuery |
||
412 | * ->select(['total_articles' => $query->func()->count('Articles.id')]) |
||
413 | * ->leftJoinWith('Articles') |
||
414 | * ->group(['Users.id']) |
||
415 | * ->autoFields(true); |
||
416 | * ``` |
||
417 | * |
||
418 | * You can also customize the conditions passed to the LEFT JOIN: |
||
419 | * |
||
420 | * ``` |
||
421 | * // Get the count of articles per user with at least 5 votes |
||
422 | * $usersQuery |
||
423 | * ->select(['total_articles' => $query->func()->count('Articles.id')]) |
||
424 | * ->leftJoinWith('Articles', function ($q) { |
||
425 | * return $q->where(['Articles.votes >=' => 5]); |
||
426 | * }) |
||
427 | * ->group(['Users.id']) |
||
428 | * ->autoFields(true); |
||
429 | * ``` |
||
430 | * |
||
431 | * This will create the following SQL: |
||
432 | * |
||
433 | * ``` |
||
434 | * SELECT COUNT(Articles.id) AS total_articles, Users.* |
||
435 | * FROM users Users |
||
436 | * LEFT JOIN articles Articles ON Articles.user_id = Users.id AND Articles.votes >= 5 |
||
437 | * GROUP BY USers.id |
||
438 | * ``` |
||
439 | * |
||
440 | * It is possible to left join deep associations by using dot notation |
||
441 | * |
||
442 | * ### Example: |
||
443 | * |
||
444 | * ``` |
||
445 | * // Total comments in articles by 'markstory' |
||
446 | * $query |
||
447 | * ->select(['total_comments' => $query->func()->count('Comments.id')]) |
||
448 | * ->leftJoinWith('Comments.Users', function ($q) { |
||
449 | * return $q->where(['username' => 'markstory']); |
||
450 | * ) |
||
451 | * ->group(['Users.id']); |
||
452 | * ``` |
||
453 | * |
||
454 | * Please note that the query passed to the closure will only accept calling |
||
455 | * `select`, `where`, `andWhere` and `orWhere` on it. If you wish to |
||
456 | * add more complex clauses you can do it directly in the main query. |
||
457 | * |
||
458 | * @param string $assoc The association to join with |
||
459 | * @param callable $builder a function that will receive a pre-made query object |
||
460 | * that can be used to add custom conditions or selecting some fields |
||
461 | * @return $this |
||
462 | */ |
||
463 | View Code Duplication | public function leftJoinWith($assoc, callable $builder = null) |
|
472 | |||
473 | /** |
||
474 | * Creates an INNER JOIN with the passed association table while preserving |
||
475 | * the foreign key matching and the custom conditions that were originally set |
||
476 | * for it. |
||
477 | * |
||
478 | * This function will add entries in the `contain` graph. |
||
479 | * |
||
480 | * ### Example: |
||
481 | * |
||
482 | * ``` |
||
483 | * // Bring only articles that were tagged with 'cake' |
||
484 | * $query->innerJoinWith('Tags', function ($q) { |
||
485 | * return $q->where(['name' => 'cake']); |
||
486 | * ); |
||
487 | * ``` |
||
488 | * |
||
489 | * This will create the following SQL: |
||
490 | * |
||
491 | * ``` |
||
492 | * SELECT Articles.* |
||
493 | * FROM articles Articles |
||
494 | * INNER JOIN tags Tags ON Tags.name = 'cake' |
||
495 | * INNER JOIN articles_tags ArticlesTags ON ArticlesTags.tag_id = Tags.id |
||
496 | * AND ArticlesTags.articles_id = Articles.id |
||
497 | * ``` |
||
498 | * |
||
499 | * This function works the same as `matching()` with the difference that it |
||
500 | * will select no fields from the association. |
||
501 | * |
||
502 | * @param string $assoc The association to join with |
||
503 | * @param callable $builder a function that will receive a pre-made query object |
||
504 | * that can be used to add custom conditions or selecting some fields |
||
505 | * @return $this |
||
506 | * @see \Cake\ORM\Query::matching() |
||
507 | */ |
||
508 | View Code Duplication | public function innerJoinWith($assoc, callable $builder = null) |
|
517 | |||
518 | /** |
||
519 | * Adds filtering conditions to this query to only bring rows that have no match |
||
520 | * to another from an associated table, based on conditions in the associated table. |
||
521 | * |
||
522 | * This function will add entries in the `contain` graph. |
||
523 | * |
||
524 | * ### Example: |
||
525 | * |
||
526 | * ``` |
||
527 | * // Bring only articles that were not tagged with 'cake' |
||
528 | * $query->notMatching('Tags', function ($q) { |
||
529 | * return $q->where(['name' => 'cake']); |
||
530 | * ); |
||
531 | * ``` |
||
532 | * |
||
533 | * It is possible to filter by deep associations by using dot notation: |
||
534 | * |
||
535 | * ### Example: |
||
536 | * |
||
537 | * ``` |
||
538 | * // Bring only articles that weren't commented by 'markstory' |
||
539 | * $query->notMatching('Comments.Users', function ($q) { |
||
540 | * return $q->where(['username' => 'markstory']); |
||
541 | * ); |
||
542 | * ``` |
||
543 | * |
||
544 | * As this function will create a `LEFT JOIN`, you might want to consider |
||
545 | * calling `distinct` on this query as you might get duplicate rows if |
||
546 | * your conditions don't filter them already. This might be the case, for example, |
||
547 | * of the same article having multiple comments. |
||
548 | * |
||
549 | * ### Example: |
||
550 | * |
||
551 | * ``` |
||
552 | * // Bring unique articles that were commented by 'markstory' |
||
553 | * $query->distinct(['Articles.id']) |
||
554 | * ->notMatching('Comments.Users', function ($q) { |
||
555 | * return $q->where(['username' => 'markstory']); |
||
556 | * ); |
||
557 | * ``` |
||
558 | * |
||
559 | * Please note that the query passed to the closure will only accept calling |
||
560 | * `select`, `where`, `andWhere` and `orWhere` on it. If you wish to |
||
561 | * add more complex clauses you can do it directly in the main query. |
||
562 | * |
||
563 | * @param string $assoc The association to filter by |
||
564 | * @param callable $builder a function that will receive a pre-made query object |
||
565 | * that can be used to add custom conditions or selecting some fields |
||
566 | * @return $this |
||
567 | */ |
||
568 | View Code Duplication | public function notMatching($assoc, callable $builder = null) |
|
578 | |||
579 | /** |
||
580 | * {@inheritDoc} |
||
581 | * |
||
582 | * Populates or adds parts to current query clauses using an array. |
||
583 | * This is handy for passing all query clauses at once. The option array accepts: |
||
584 | * |
||
585 | * - fields: Maps to the select method |
||
586 | * - conditions: Maps to the where method |
||
587 | * - limit: Maps to the limit method |
||
588 | * - order: Maps to the order method |
||
589 | * - offset: Maps to the offset method |
||
590 | * - group: Maps to the group method |
||
591 | * - having: Maps to the having method |
||
592 | * - contain: Maps to the contain options for eager loading |
||
593 | * - join: Maps to the join method |
||
594 | * - page: Maps to the page method |
||
595 | * |
||
596 | * ### Example: |
||
597 | * |
||
598 | * ``` |
||
599 | * $query->applyOptions([ |
||
600 | * 'fields' => ['id', 'name'], |
||
601 | * 'conditions' => [ |
||
602 | * 'created >=' => '2013-01-01' |
||
603 | * ], |
||
604 | * 'limit' => 10 |
||
605 | * ]); |
||
606 | * ``` |
||
607 | * |
||
608 | * Is equivalent to: |
||
609 | * |
||
610 | * ``` |
||
611 | * $query |
||
612 | * ->select(['id', 'name']) |
||
613 | * ->where(['created >=' => '2013-01-01']) |
||
614 | * ->limit(10) |
||
615 | * ``` |
||
616 | */ |
||
617 | public function applyOptions(array $options) |
||
643 | |||
644 | /** |
||
645 | * Creates a copy of this current query, triggers beforeFind and resets some state. |
||
646 | * |
||
647 | * The following state will be cleared: |
||
648 | * |
||
649 | * - autoFields |
||
650 | * - limit |
||
651 | * - offset |
||
652 | * - map/reduce functions |
||
653 | * - result formatters |
||
654 | * - order |
||
655 | * - containments |
||
656 | * |
||
657 | * This method creates query clones that are useful when working with subqueries. |
||
658 | * |
||
659 | * @return \Cake\ORM\Query |
||
660 | */ |
||
661 | public function cleanCopy() |
||
673 | |||
674 | /** |
||
675 | * Object clone hook. |
||
676 | * |
||
677 | * Destroys the clones inner iterator and clones the value binder, and eagerloader instances. |
||
678 | * |
||
679 | * @return void |
||
680 | */ |
||
681 | public function __clone() |
||
688 | |||
689 | /** |
||
690 | * {@inheritDoc} |
||
691 | * |
||
692 | * Returns the COUNT(*) for the query. If the query has not been |
||
693 | * modified, and the count has already been performed the cached |
||
694 | * value is returned |
||
695 | */ |
||
696 | public function count() |
||
704 | |||
705 | /** |
||
706 | * Performs and returns the COUNT(*) for the query. |
||
707 | * |
||
708 | * @return int |
||
709 | */ |
||
710 | protected function _performCount() |
||
760 | |||
761 | /** |
||
762 | * Registers a callable function that will be executed when the `count` method in |
||
763 | * this query is called. The return value for the function will be set as the |
||
764 | * return value of the `count` method. |
||
765 | * |
||
766 | * This is particularly useful when you need to optimize a query for returning the |
||
767 | * count, for example removing unnecessary joins, removing group by or just return |
||
768 | * an estimated number of rows. |
||
769 | * |
||
770 | * The callback will receive as first argument a clone of this query and not this |
||
771 | * query itself. |
||
772 | * |
||
773 | * If the first param is a null value, the built-in counter function will be called |
||
774 | * instead |
||
775 | * |
||
776 | * @param callable|null $counter The counter value |
||
777 | * @return $this |
||
778 | */ |
||
779 | public function counter($counter) |
||
784 | |||
785 | /** |
||
786 | * Toggle hydrating entities. |
||
787 | * |
||
788 | * If set to false array results will be returned |
||
789 | * |
||
790 | * @param bool|null $enable Use a boolean to set the hydration mode. |
||
791 | * Null will fetch the current hydration mode. |
||
792 | * @return bool|$this A boolean when reading, and $this when setting the mode. |
||
793 | */ |
||
794 | public function hydrate($enable = null) |
||
804 | |||
805 | /** |
||
806 | * {@inheritDoc} |
||
807 | * |
||
808 | * @return $this |
||
809 | * @throws \RuntimeException When you attempt to cache a non-select query. |
||
810 | */ |
||
811 | public function cache($key, $config = 'default') |
||
818 | |||
819 | /** |
||
820 | * {@inheritDoc} |
||
821 | * |
||
822 | * @throws \RuntimeException if this method is called on a non-select Query. |
||
823 | */ |
||
824 | public function all() |
||
833 | |||
834 | /** |
||
835 | * Trigger the beforeFind event on the query's repository object. |
||
836 | * |
||
837 | * Will not trigger more than once, and only for select queries. |
||
838 | * |
||
839 | * @return void |
||
840 | */ |
||
841 | public function triggerBeforeFind() |
||
853 | |||
854 | /** |
||
855 | * {@inheritDoc} |
||
856 | */ |
||
857 | public function sql(ValueBinder $binder = null) |
||
865 | |||
866 | /** |
||
867 | * Executes this query and returns a ResultSet object containing the results. |
||
868 | * This will also setup the correct statement class in order to eager load deep |
||
869 | * associations. |
||
870 | * |
||
871 | * @return \Cake\ORM\ResultSet |
||
872 | */ |
||
873 | protected function _execute() |
||
883 | |||
884 | /** |
||
885 | * Applies some defaults to the query object before it is executed. |
||
886 | * |
||
887 | * Specifically add the FROM clause, adds default table fields if none are |
||
888 | * specified and applies the joins required to eager load associations defined |
||
889 | * using `contain` |
||
890 | * |
||
891 | * @see \Cake\Database\Query::execute() |
||
892 | * @return void |
||
893 | */ |
||
894 | protected function _transformQuery() |
||
908 | |||
909 | /** |
||
910 | * Inspects if there are any set fields for selecting, otherwise adds all |
||
911 | * the fields for the default table. |
||
912 | * |
||
913 | * @return void |
||
914 | */ |
||
915 | protected function _addDefaultFields() |
||
929 | |||
930 | /** |
||
931 | * {@inheritDoc} |
||
932 | * |
||
933 | * @see \Cake\ORM\Table::find() |
||
934 | */ |
||
935 | public function find($finder, array $options = []) |
||
939 | |||
940 | /** |
||
941 | * Marks a query as dirty, removing any preprocessed information |
||
942 | * from in memory caching such as previous results |
||
943 | * |
||
944 | * @return void |
||
945 | */ |
||
946 | protected function _dirty() |
||
952 | |||
953 | /** |
||
954 | * Create an update query. |
||
955 | * |
||
956 | * This changes the query type to be 'update'. |
||
957 | * Can be combined with set() and where() methods to create update queries. |
||
958 | * |
||
959 | * @param string|null $table Unused parameter. |
||
960 | * @return $this |
||
961 | */ |
||
962 | public function update($table = null) |
||
967 | |||
968 | /** |
||
969 | * Create a delete query. |
||
970 | * |
||
971 | * This changes the query type to be 'delete'. |
||
972 | * Can be combined with the where() method to create delete queries. |
||
973 | * |
||
974 | * @param string|null $table Unused parameter. |
||
975 | * @return $this |
||
976 | */ |
||
977 | public function delete($table = null) |
||
983 | |||
984 | /** |
||
985 | * Create an insert query. |
||
986 | * |
||
987 | * This changes the query type to be 'insert'. |
||
988 | * Note calling this method will reset any data previously set |
||
989 | * with Query::values() |
||
990 | * |
||
991 | * Can be combined with the where() method to create delete queries. |
||
992 | * |
||
993 | * @param array $columns The columns to insert into. |
||
994 | * @param array $types A map between columns & their datatypes. |
||
995 | * @return $this |
||
996 | */ |
||
997 | public function insert(array $columns, array $types = []) |
||
1003 | |||
1004 | /** |
||
1005 | * {@inheritDoc} |
||
1006 | * |
||
1007 | * @throws \BadMethodCallException if the method is called for a non-select query |
||
1008 | */ |
||
1009 | public function __call($method, $arguments) |
||
1019 | |||
1020 | /** |
||
1021 | * {@inheritDoc} |
||
1022 | */ |
||
1023 | public function __debugInfo() |
||
1037 | |||
1038 | /** |
||
1039 | * Executes the query and converts the result set into JSON. |
||
1040 | * |
||
1041 | * Part of JsonSerializable interface. |
||
1042 | * |
||
1043 | * @return \Cake\Datasource\ResultSetInterface The data to convert to JSON. |
||
1044 | */ |
||
1045 | public function jsonSerialize() |
||
1049 | |||
1050 | /** |
||
1051 | * Get/Set whether or not the ORM should automatically append fields. |
||
1052 | * |
||
1053 | * By default calling select() will disable auto-fields. You can re-enable |
||
1054 | * auto-fields with this method. |
||
1055 | * |
||
1056 | * @param bool|null $value The value to set or null to read the current value. |
||
1057 | * @return bool|$this Either the current value or the query object. |
||
1058 | */ |
||
1059 | public function autoFields($value = null) |
||
1067 | |||
1068 | /** |
||
1069 | * Decorates the results iterator with MapReduce routines and formatters |
||
1070 | * |
||
1071 | * @param \Traversable $result Original results |
||
1072 | * @return \Cake\Datasource\ResultSetInterface |
||
1073 | */ |
||
1074 | protected function _decorateResults($result) |
||
1085 | } |
||
1086 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.