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 BannerImageQuery 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 BannerImageQuery, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
119 | abstract class BannerImageQuery extends ModelCriteria |
||
120 | { |
||
121 | protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException'; |
||
122 | |||
123 | /** |
||
124 | * Initializes internal state of \xbanners\models\Base\BannerImageQuery object. |
||
125 | * |
||
126 | * @param string $dbName The database name |
||
127 | * @param string $modelName The phpName of a model, e.g. 'Book' |
||
128 | * @param string $modelAlias The alias for the model in this query, e.g. 'b' |
||
129 | */ |
||
130 | public function __construct($dbName = 'Shop', $modelName = '\\xbanners\\models\\BannerImage', $modelAlias = null) |
||
134 | |||
135 | /** |
||
136 | * Returns a new ChildBannerImageQuery object. |
||
137 | * |
||
138 | * @param string $modelAlias The alias of a model in the query |
||
139 | * @param Criteria $criteria Optional Criteria to build the query from |
||
140 | * |
||
141 | * @return ChildBannerImageQuery |
||
142 | */ |
||
143 | View Code Duplication | public static function create($modelAlias = null, Criteria $criteria = null) |
|
158 | |||
159 | /** |
||
160 | * Find object by primary key. |
||
161 | * Propel uses the instance pool to skip the database if the object exists. |
||
162 | * Go fast if the query is untouched. |
||
163 | * |
||
164 | * <code> |
||
165 | * $obj = $c->findPk(12, $con); |
||
166 | * </code> |
||
167 | * |
||
168 | * @param mixed $key Primary key to use for the query |
||
169 | * @param ConnectionInterface $con an optional connection object |
||
170 | * |
||
171 | * @return ChildBannerImage|array|mixed the result, formatted by the current formatter |
||
172 | */ |
||
173 | View Code Duplication | public function findPk($key, ConnectionInterface $con = null) |
|
194 | |||
195 | /** |
||
196 | * Find object by primary key using raw SQL to go fast. |
||
197 | * Bypass doSelect() and the object formatter by using generated code. |
||
198 | * |
||
199 | * @param mixed $key Primary key to use for the query |
||
200 | * @param ConnectionInterface $con A connection object |
||
201 | * |
||
202 | * @throws \Propel\Runtime\Exception\PropelException |
||
203 | * |
||
204 | * @return ChildBannerImage A model object, or null if the key is not found |
||
205 | */ |
||
206 | View Code Duplication | protected function findPkSimple($key, ConnectionInterface $con) |
|
228 | |||
229 | /** |
||
230 | * Find object by primary key. |
||
231 | * |
||
232 | * @param mixed $key Primary key to use for the query |
||
233 | * @param ConnectionInterface $con A connection object |
||
234 | * |
||
235 | * @return ChildBannerImage|array|mixed the result, formatted by the current formatter |
||
236 | */ |
||
237 | View Code Duplication | protected function findPkComplex($key, ConnectionInterface $con) |
|
247 | |||
248 | /** |
||
249 | * Find objects by primary key |
||
250 | * <code> |
||
251 | * $objs = $c->findPks(array(12, 56, 832), $con); |
||
252 | * </code> |
||
253 | * @param array $keys Primary keys to use for the query |
||
254 | * @param ConnectionInterface $con an optional connection object |
||
255 | * |
||
256 | * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter |
||
257 | */ |
||
258 | View Code Duplication | public function findPks($keys, ConnectionInterface $con = null) |
|
271 | |||
272 | /** |
||
273 | * Filter the query by primary key |
||
274 | * |
||
275 | * @param mixed $key Primary key to use for the query |
||
276 | * |
||
277 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
278 | */ |
||
279 | public function filterByPrimaryKey($key) |
||
284 | |||
285 | /** |
||
286 | * Filter the query by a list of primary keys |
||
287 | * |
||
288 | * @param array $keys The list of primary key to use for the query |
||
289 | * |
||
290 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
291 | */ |
||
292 | public function filterByPrimaryKeys($keys) |
||
297 | |||
298 | /** |
||
299 | * Filter the query on the id column |
||
300 | * |
||
301 | * Example usage: |
||
302 | * <code> |
||
303 | * $query->filterById(1234); // WHERE id = 1234 |
||
304 | * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) |
||
305 | * $query->filterById(array('min' => 12)); // WHERE id > 12 |
||
306 | * </code> |
||
307 | * |
||
308 | * @param mixed $id The value to use as filter. |
||
309 | * Use scalar values for equality. |
||
310 | * Use array values for in_array() equivalent. |
||
311 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
312 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
313 | * |
||
314 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
315 | */ |
||
316 | View Code Duplication | public function filterById($id = null, $comparison = null) |
|
338 | |||
339 | /** |
||
340 | * Filter the query on the banner_id column |
||
341 | * |
||
342 | * Example usage: |
||
343 | * <code> |
||
344 | * $query->filterByBannerId(1234); // WHERE banner_id = 1234 |
||
345 | * $query->filterByBannerId(array(12, 34)); // WHERE banner_id IN (12, 34) |
||
346 | * $query->filterByBannerId(array('min' => 12)); // WHERE banner_id > 12 |
||
347 | * </code> |
||
348 | * |
||
349 | * @see filterByBanners() |
||
350 | * |
||
351 | * @param mixed $bannerId The value to use as filter. |
||
352 | * Use scalar values for equality. |
||
353 | * Use array values for in_array() equivalent. |
||
354 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
355 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
356 | * |
||
357 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
358 | */ |
||
359 | View Code Duplication | public function filterByBannerId($bannerId = null, $comparison = null) |
|
381 | |||
382 | /** |
||
383 | * Filter the query on the target column |
||
384 | * |
||
385 | * Example usage: |
||
386 | * <code> |
||
387 | * $query->filterByTarget(1234); // WHERE target = 1234 |
||
388 | * $query->filterByTarget(array(12, 34)); // WHERE target IN (12, 34) |
||
389 | * $query->filterByTarget(array('min' => 12)); // WHERE target > 12 |
||
390 | * </code> |
||
391 | * |
||
392 | * @param mixed $target The value to use as filter. |
||
393 | * Use scalar values for equality. |
||
394 | * Use array values for in_array() equivalent. |
||
395 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
396 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
397 | * |
||
398 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
399 | */ |
||
400 | View Code Duplication | public function filterByTarget($target = null, $comparison = null) |
|
422 | |||
423 | /** |
||
424 | * Filter the query on the url column |
||
425 | * |
||
426 | * Example usage: |
||
427 | * <code> |
||
428 | * $query->filterByUrl('fooValue'); // WHERE url = 'fooValue' |
||
429 | * $query->filterByUrl('%fooValue%'); // WHERE url LIKE '%fooValue%' |
||
430 | * </code> |
||
431 | * |
||
432 | * @param string $url The value to use as filter. |
||
433 | * Accepts wildcards (* and % trigger a LIKE) |
||
434 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
435 | * |
||
436 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
437 | */ |
||
438 | View Code Duplication | public function filterByUrl($url = null, $comparison = null) |
|
451 | |||
452 | /** |
||
453 | * Filter the query on the allowed_page column |
||
454 | * |
||
455 | * Example usage: |
||
456 | * <code> |
||
457 | * $query->filterByAllowedPage(1234); // WHERE allowed_page = 1234 |
||
458 | * $query->filterByAllowedPage(array(12, 34)); // WHERE allowed_page IN (12, 34) |
||
459 | * $query->filterByAllowedPage(array('min' => 12)); // WHERE allowed_page > 12 |
||
460 | * </code> |
||
461 | * |
||
462 | * @param mixed $allowedPage The value to use as filter. |
||
463 | * Use scalar values for equality. |
||
464 | * Use array values for in_array() equivalent. |
||
465 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
466 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
467 | * |
||
468 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
469 | */ |
||
470 | View Code Duplication | public function filterByAllowedPage($allowedPage = null, $comparison = null) |
|
492 | |||
493 | /** |
||
494 | * Filter the query on the position column |
||
495 | * |
||
496 | * Example usage: |
||
497 | * <code> |
||
498 | * $query->filterByPosition(1234); // WHERE position = 1234 |
||
499 | * $query->filterByPosition(array(12, 34)); // WHERE position IN (12, 34) |
||
500 | * $query->filterByPosition(array('min' => 12)); // WHERE position > 12 |
||
501 | * </code> |
||
502 | * |
||
503 | * @param mixed $position The value to use as filter. |
||
504 | * Use scalar values for equality. |
||
505 | * Use array values for in_array() equivalent. |
||
506 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
507 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
508 | * |
||
509 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
510 | */ |
||
511 | View Code Duplication | public function filterByPosition($position = null, $comparison = null) |
|
533 | |||
534 | /** |
||
535 | * Filter the query on the active_from column |
||
536 | * |
||
537 | * Example usage: |
||
538 | * <code> |
||
539 | * $query->filterByActiveFrom(1234); // WHERE active_from = 1234 |
||
540 | * $query->filterByActiveFrom(array(12, 34)); // WHERE active_from IN (12, 34) |
||
541 | * $query->filterByActiveFrom(array('min' => 12)); // WHERE active_from > 12 |
||
542 | * </code> |
||
543 | * |
||
544 | * @param mixed $activeFrom The value to use as filter. |
||
545 | * Use scalar values for equality. |
||
546 | * Use array values for in_array() equivalent. |
||
547 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
548 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
549 | * |
||
550 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
551 | */ |
||
552 | View Code Duplication | public function filterByActiveFrom($activeFrom = null, $comparison = null) |
|
574 | |||
575 | /** |
||
576 | * Filter the query on the active_to column |
||
577 | * |
||
578 | * Example usage: |
||
579 | * <code> |
||
580 | * $query->filterByActiveTo(1234); // WHERE active_to = 1234 |
||
581 | * $query->filterByActiveTo(array(12, 34)); // WHERE active_to IN (12, 34) |
||
582 | * $query->filterByActiveTo(array('min' => 12)); // WHERE active_to > 12 |
||
583 | * </code> |
||
584 | * |
||
585 | * @param mixed $activeTo The value to use as filter. |
||
586 | * Use scalar values for equality. |
||
587 | * Use array values for in_array() equivalent. |
||
588 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
589 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
590 | * |
||
591 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
592 | */ |
||
593 | View Code Duplication | public function filterByActiveTo($activeTo = null, $comparison = null) |
|
615 | |||
616 | /** |
||
617 | * Filter the query on the active column |
||
618 | * |
||
619 | * Example usage: |
||
620 | * <code> |
||
621 | * $query->filterByActive(1234); // WHERE active = 1234 |
||
622 | * $query->filterByActive(array(12, 34)); // WHERE active IN (12, 34) |
||
623 | * $query->filterByActive(array('min' => 12)); // WHERE active > 12 |
||
624 | * </code> |
||
625 | * |
||
626 | * @param mixed $active The value to use as filter. |
||
627 | * Use scalar values for equality. |
||
628 | * Use array values for in_array() equivalent. |
||
629 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
630 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
631 | * |
||
632 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
633 | */ |
||
634 | View Code Duplication | public function filterByActive($active = null, $comparison = null) |
|
656 | |||
657 | /** |
||
658 | * Filter the query on the permanent column |
||
659 | * |
||
660 | * Example usage: |
||
661 | * <code> |
||
662 | * $query->filterByPermanent(1234); // WHERE permanent = 1234 |
||
663 | * $query->filterByPermanent(array(12, 34)); // WHERE permanent IN (12, 34) |
||
664 | * $query->filterByPermanent(array('min' => 12)); // WHERE permanent > 12 |
||
665 | * </code> |
||
666 | * |
||
667 | * @param mixed $permanent The value to use as filter. |
||
668 | * Use scalar values for equality. |
||
669 | * Use array values for in_array() equivalent. |
||
670 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
671 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
672 | * |
||
673 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
674 | */ |
||
675 | View Code Duplication | public function filterByPermanent($permanent = null, $comparison = null) |
|
697 | |||
698 | /** |
||
699 | * Filter the query by a related \xbanners\models\Banners object |
||
700 | * |
||
701 | * @param \xbanners\models\Banners|ObjectCollection $banners The related object(s) to use as filter |
||
702 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
703 | * |
||
704 | * @throws \Propel\Runtime\Exception\PropelException |
||
705 | * |
||
706 | * @return ChildBannerImageQuery The current query, for fluid interface |
||
707 | */ |
||
708 | View Code Duplication | public function filterByBanners($banners, $comparison = null) |
|
724 | |||
725 | /** |
||
726 | * Adds a JOIN clause to the query using the Banners relation |
||
727 | * |
||
728 | * @param string $relationAlias optional alias for the relation |
||
729 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
730 | * |
||
731 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
732 | */ |
||
733 | View Code Duplication | public function joinBanners($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
|
756 | |||
757 | /** |
||
758 | * Use the Banners relation Banners object |
||
759 | * |
||
760 | * @see useQuery() |
||
761 | * |
||
762 | * @param string $relationAlias optional alias for the relation, |
||
763 | * to be used as main alias in the secondary query |
||
764 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
765 | * |
||
766 | * @return \xbanners\models\BannersQuery A secondary query class using the current class as primary query |
||
767 | */ |
||
768 | public function useBannersQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
||
774 | |||
775 | /** |
||
776 | * Filter the query by a related \xbanners\models\BannerImageI18n object |
||
777 | * |
||
778 | * @param \xbanners\models\BannerImageI18n|ObjectCollection $bannerImageI18n the related object to use as filter |
||
779 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
780 | * |
||
781 | * @return ChildBannerImageQuery The current query, for fluid interface |
||
782 | */ |
||
783 | View Code Duplication | public function filterByBannerImageI18n($bannerImageI18n, $comparison = null) |
|
797 | |||
798 | /** |
||
799 | * Adds a JOIN clause to the query using the BannerImageI18n relation |
||
800 | * |
||
801 | * @param string $relationAlias optional alias for the relation |
||
802 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
803 | * |
||
804 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
805 | */ |
||
806 | View Code Duplication | public function joinBannerImageI18n($relationAlias = null, $joinType = 'LEFT JOIN') |
|
829 | |||
830 | /** |
||
831 | * Use the BannerImageI18n relation BannerImageI18n object |
||
832 | * |
||
833 | * @see useQuery() |
||
834 | * |
||
835 | * @param string $relationAlias optional alias for the relation, |
||
836 | * to be used as main alias in the secondary query |
||
837 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
838 | * |
||
839 | * @return \xbanners\models\BannerImageI18nQuery A secondary query class using the current class as primary query |
||
840 | */ |
||
841 | public function useBannerImageI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') |
||
847 | |||
848 | /** |
||
849 | * Exclude object from result |
||
850 | * |
||
851 | * @param ChildBannerImage $bannerImage Object to remove from the list of results |
||
852 | * |
||
853 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
854 | */ |
||
855 | public function prune($bannerImage = null) |
||
863 | |||
864 | /** |
||
865 | * Deletes all rows from the banner_image table. |
||
866 | * |
||
867 | * @param ConnectionInterface $con the connection to use |
||
868 | * @return int The number of affected rows (if supported by underlying database driver). |
||
869 | */ |
||
870 | View Code Duplication | public function doDeleteAll(ConnectionInterface $con = null) |
|
891 | |||
892 | /** |
||
893 | * Performs a DELETE on the database based on the current ModelCriteria |
||
894 | * |
||
895 | * @param ConnectionInterface $con the connection to use |
||
896 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
897 | * if supported by native driver or if emulated using Propel. |
||
898 | * @throws PropelException Any exceptions caught during processing will be |
||
899 | * rethrown wrapped into a PropelException. |
||
900 | */ |
||
901 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
929 | |||
930 | /** |
||
931 | * This is a method for emulating ON DELETE CASCADE for DBs that don't support this |
||
932 | * feature (like MySQL or SQLite). |
||
933 | * |
||
934 | * This method is not very speedy because it must perform a query first to get |
||
935 | * the implicated records and then perform the deletes by calling those Query classes. |
||
936 | * |
||
937 | * This method should be used within a transaction if possible. |
||
938 | * |
||
939 | * @param ConnectionInterface $con |
||
940 | * @return int The number of affected rows (if supported by underlying database driver). |
||
941 | */ |
||
942 | protected function doOnDeleteCascade(ConnectionInterface $con) |
||
961 | |||
962 | // i18n behavior |
||
963 | |||
964 | /** |
||
965 | * Adds a JOIN clause to the query using the i18n relation |
||
966 | * |
||
967 | * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' |
||
968 | * @param string $relationAlias optional alias for the relation |
||
969 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. |
||
970 | * |
||
971 | * @return ChildBannerImageQuery The current query, for fluid interface |
||
972 | */ |
||
973 | View Code Duplication | public function joinI18n($locale = 'ru', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
|
981 | |||
982 | /** |
||
983 | * Adds a JOIN clause to the query and hydrates the related I18n object. |
||
984 | * Shortcut for $c->joinI18n($locale)->with() |
||
985 | * |
||
986 | * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' |
||
987 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. |
||
988 | * |
||
989 | * @return $this|ChildBannerImageQuery The current query, for fluid interface |
||
990 | */ |
||
991 | View Code Duplication | public function joinWithI18n($locale = 'ru', $joinType = Criteria::LEFT_JOIN) |
|
1000 | |||
1001 | /** |
||
1002 | * Use the I18n relation query object |
||
1003 | * |
||
1004 | * @see useQuery() |
||
1005 | * |
||
1006 | * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' |
||
1007 | * @param string $relationAlias optional alias for the relation |
||
1008 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. |
||
1009 | * |
||
1010 | * @return ChildBannerImageI18nQuery A secondary query class using the current class as primary query |
||
1011 | */ |
||
1012 | public function useI18nQuery($locale = 'ru', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
||
1018 | |||
1019 | } // BannerImageQuery |
||
1020 |