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 BannersQuery 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 BannersQuery, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
100 | abstract class BannersQuery extends ModelCriteria |
||
101 | { |
||
102 | protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException'; |
||
103 | |||
104 | /** |
||
105 | * Initializes internal state of \xbanners\models\Base\BannersQuery object. |
||
106 | * |
||
107 | * @param string $dbName The database name |
||
108 | * @param string $modelName The phpName of a model, e.g. 'Book' |
||
109 | * @param string $modelAlias The alias for the model in this query, e.g. 'b' |
||
110 | */ |
||
111 | public function __construct($dbName = 'Shop', $modelName = '\\xbanners\\models\\Banners', $modelAlias = null) |
||
115 | |||
116 | /** |
||
117 | * Returns a new ChildBannersQuery object. |
||
118 | * |
||
119 | * @param string $modelAlias The alias of a model in the query |
||
120 | * @param Criteria $criteria Optional Criteria to build the query from |
||
121 | * |
||
122 | * @return ChildBannersQuery |
||
123 | */ |
||
124 | View Code Duplication | public static function create($modelAlias = null, Criteria $criteria = null) |
|
139 | |||
140 | /** |
||
141 | * Find object by primary key. |
||
142 | * Propel uses the instance pool to skip the database if the object exists. |
||
143 | * Go fast if the query is untouched. |
||
144 | * |
||
145 | * <code> |
||
146 | * $obj = $c->findPk(12, $con); |
||
147 | * </code> |
||
148 | * |
||
149 | * @param mixed $key Primary key to use for the query |
||
150 | * @param ConnectionInterface $con an optional connection object |
||
151 | * |
||
152 | * @return ChildBanners|array|mixed the result, formatted by the current formatter |
||
153 | */ |
||
154 | public function findPk($key, ConnectionInterface $con = null) |
||
181 | |||
182 | /** |
||
183 | * Find object by primary key using raw SQL to go fast. |
||
184 | * Bypass doSelect() and the object formatter by using generated code. |
||
185 | * |
||
186 | * @param mixed $key Primary key to use for the query |
||
187 | * @param ConnectionInterface $con A connection object |
||
188 | * |
||
189 | * @throws \Propel\Runtime\Exception\PropelException |
||
190 | * |
||
191 | * @return ChildBanners A model object, or null if the key is not found |
||
192 | */ |
||
193 | View Code Duplication | protected function findPkSimple($key, ConnectionInterface $con) |
|
215 | |||
216 | /** |
||
217 | * Find object by primary key. |
||
218 | * |
||
219 | * @param mixed $key Primary key to use for the query |
||
220 | * @param ConnectionInterface $con A connection object |
||
221 | * |
||
222 | * @return ChildBanners|array|mixed the result, formatted by the current formatter |
||
223 | */ |
||
224 | View Code Duplication | protected function findPkComplex($key, ConnectionInterface $con) |
|
234 | |||
235 | /** |
||
236 | * Find objects by primary key |
||
237 | * <code> |
||
238 | * $objs = $c->findPks(array(12, 56, 832), $con); |
||
239 | * </code> |
||
240 | * @param array $keys Primary keys to use for the query |
||
241 | * @param ConnectionInterface $con an optional connection object |
||
242 | * |
||
243 | * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter |
||
244 | */ |
||
245 | View Code Duplication | public function findPks($keys, ConnectionInterface $con = null) |
|
258 | |||
259 | /** |
||
260 | * Filter the query by primary key |
||
261 | * |
||
262 | * @param mixed $key Primary key to use for the query |
||
263 | * |
||
264 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
265 | */ |
||
266 | public function filterByPrimaryKey($key) |
||
271 | |||
272 | /** |
||
273 | * Filter the query by a list of primary keys |
||
274 | * |
||
275 | * @param array $keys The list of primary key to use for the query |
||
276 | * |
||
277 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
278 | */ |
||
279 | public function filterByPrimaryKeys($keys) |
||
284 | |||
285 | /** |
||
286 | * Filter the query on the id column |
||
287 | * |
||
288 | * Example usage: |
||
289 | * <code> |
||
290 | * $query->filterById(1234); // WHERE id = 1234 |
||
291 | * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) |
||
292 | * $query->filterById(array('min' => 12)); // WHERE id > 12 |
||
293 | * </code> |
||
294 | * |
||
295 | * @param mixed $id The value to use as filter. |
||
296 | * Use scalar values for equality. |
||
297 | * Use array values for in_array() equivalent. |
||
298 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
299 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
300 | * |
||
301 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
302 | */ |
||
303 | View Code Duplication | public function filterById($id = null, $comparison = null) |
|
325 | |||
326 | /** |
||
327 | * Filter the query on the place column |
||
328 | * |
||
329 | * Example usage: |
||
330 | * <code> |
||
331 | * $query->filterByPlace('fooValue'); // WHERE place = 'fooValue' |
||
332 | * $query->filterByPlace('%fooValue%'); // WHERE place LIKE '%fooValue%' |
||
333 | * </code> |
||
334 | * |
||
335 | * @param string $place The value to use as filter. |
||
336 | * Accepts wildcards (* and % trigger a LIKE) |
||
337 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
338 | * |
||
339 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
340 | */ |
||
341 | View Code Duplication | public function filterByPlace($place = null, $comparison = null) |
|
354 | |||
355 | /** |
||
356 | * Filter the query on the width column |
||
357 | * |
||
358 | * Example usage: |
||
359 | * <code> |
||
360 | * $query->filterByWidth(1234); // WHERE width = 1234 |
||
361 | * $query->filterByWidth(array(12, 34)); // WHERE width IN (12, 34) |
||
362 | * $query->filterByWidth(array('min' => 12)); // WHERE width > 12 |
||
363 | * </code> |
||
364 | * |
||
365 | * @param mixed $width The value to use as filter. |
||
366 | * Use scalar values for equality. |
||
367 | * Use array values for in_array() equivalent. |
||
368 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
369 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
370 | * |
||
371 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
372 | */ |
||
373 | View Code Duplication | public function filterByWidth($width = null, $comparison = null) |
|
395 | |||
396 | /** |
||
397 | * Filter the query on the height column |
||
398 | * |
||
399 | * Example usage: |
||
400 | * <code> |
||
401 | * $query->filterByHeight(1234); // WHERE height = 1234 |
||
402 | * $query->filterByHeight(array(12, 34)); // WHERE height IN (12, 34) |
||
403 | * $query->filterByHeight(array('min' => 12)); // WHERE height > 12 |
||
404 | * </code> |
||
405 | * |
||
406 | * @param mixed $height The value to use as filter. |
||
407 | * Use scalar values for equality. |
||
408 | * Use array values for in_array() equivalent. |
||
409 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
410 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
411 | * |
||
412 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
413 | */ |
||
414 | View Code Duplication | public function filterByHeight($height = null, $comparison = null) |
|
436 | |||
437 | /** |
||
438 | * Filter the query on the effects column |
||
439 | * |
||
440 | * Example usage: |
||
441 | * <code> |
||
442 | * $query->filterByEffects('fooValue'); // WHERE effects = 'fooValue' |
||
443 | * $query->filterByEffects('%fooValue%'); // WHERE effects LIKE '%fooValue%' |
||
444 | * </code> |
||
445 | * |
||
446 | * @param string $effects The value to use as filter. |
||
447 | * Accepts wildcards (* and % trigger a LIKE) |
||
448 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
449 | * |
||
450 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
451 | */ |
||
452 | View Code Duplication | public function filterByEffects($effects = null, $comparison = null) |
|
465 | |||
466 | /** |
||
467 | * Filter the query on the page_type column |
||
468 | * |
||
469 | * Example usage: |
||
470 | * <code> |
||
471 | * $query->filterByPageType('fooValue'); // WHERE page_type = 'fooValue' |
||
472 | * $query->filterByPageType('%fooValue%'); // WHERE page_type LIKE '%fooValue%' |
||
473 | * </code> |
||
474 | * |
||
475 | * @param string $pageType The value to use as filter. |
||
476 | * Accepts wildcards (* and % trigger a LIKE) |
||
477 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
478 | * |
||
479 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
480 | */ |
||
481 | View Code Duplication | public function filterByPageType($pageType = null, $comparison = null) |
|
494 | |||
495 | /** |
||
496 | * Filter the query by a related \xbanners\models\BannerImage object |
||
497 | * |
||
498 | * @param \xbanners\models\BannerImage|ObjectCollection $bannerImage the related object to use as filter |
||
499 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
500 | * |
||
501 | * @return ChildBannersQuery The current query, for fluid interface |
||
502 | */ |
||
503 | View Code Duplication | public function filterByBannerImage($bannerImage, $comparison = null) |
|
517 | |||
518 | /** |
||
519 | * Adds a JOIN clause to the query using the BannerImage relation |
||
520 | * |
||
521 | * @param string $relationAlias optional alias for the relation |
||
522 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
523 | * |
||
524 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
525 | */ |
||
526 | View Code Duplication | public function joinBannerImage($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
|
549 | |||
550 | /** |
||
551 | * Use the BannerImage relation BannerImage object |
||
552 | * |
||
553 | * @see useQuery() |
||
554 | * |
||
555 | * @param string $relationAlias optional alias for the relation, |
||
556 | * to be used as main alias in the secondary query |
||
557 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
558 | * |
||
559 | * @return \xbanners\models\BannerImageQuery A secondary query class using the current class as primary query |
||
560 | */ |
||
561 | public function useBannerImageQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
||
567 | |||
568 | /** |
||
569 | * Filter the query by a related \xbanners\models\BannersI18n object |
||
570 | * |
||
571 | * @param \xbanners\models\BannersI18n|ObjectCollection $bannersI18n the related object to use as filter |
||
572 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
573 | * |
||
574 | * @return ChildBannersQuery The current query, for fluid interface |
||
575 | */ |
||
576 | View Code Duplication | public function filterByBannersI18n($bannersI18n, $comparison = null) |
|
590 | |||
591 | /** |
||
592 | * Adds a JOIN clause to the query using the BannersI18n relation |
||
593 | * |
||
594 | * @param string $relationAlias optional alias for the relation |
||
595 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
596 | * |
||
597 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
598 | */ |
||
599 | View Code Duplication | public function joinBannersI18n($relationAlias = null, $joinType = 'LEFT JOIN') |
|
622 | |||
623 | /** |
||
624 | * Use the BannersI18n relation BannersI18n object |
||
625 | * |
||
626 | * @see useQuery() |
||
627 | * |
||
628 | * @param string $relationAlias optional alias for the relation, |
||
629 | * to be used as main alias in the secondary query |
||
630 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
631 | * |
||
632 | * @return \xbanners\models\BannersI18nQuery A secondary query class using the current class as primary query |
||
633 | */ |
||
634 | public function useBannersI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') |
||
640 | |||
641 | /** |
||
642 | * Exclude object from result |
||
643 | * |
||
644 | * @param ChildBanners $banners Object to remove from the list of results |
||
645 | * |
||
646 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
647 | */ |
||
648 | public function prune($banners = null) |
||
656 | |||
657 | /** |
||
658 | * Deletes all rows from the banners table. |
||
659 | * |
||
660 | * @param ConnectionInterface $con the connection to use |
||
661 | * @return int The number of affected rows (if supported by underlying database driver). |
||
662 | */ |
||
663 | View Code Duplication | public function doDeleteAll(ConnectionInterface $con = null) |
|
684 | |||
685 | /** |
||
686 | * Performs a DELETE on the database based on the current ModelCriteria |
||
687 | * |
||
688 | * @param ConnectionInterface $con the connection to use |
||
689 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
690 | * if supported by native driver or if emulated using Propel. |
||
691 | * @throws PropelException Any exceptions caught during processing will be |
||
692 | * rethrown wrapped into a PropelException. |
||
693 | */ |
||
694 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
722 | |||
723 | /** |
||
724 | * This is a method for emulating ON DELETE CASCADE for DBs that don't support this |
||
725 | * feature (like MySQL or SQLite). |
||
726 | * |
||
727 | * This method is not very speedy because it must perform a query first to get |
||
728 | * the implicated records and then perform the deletes by calling those Query classes. |
||
729 | * |
||
730 | * This method should be used within a transaction if possible. |
||
731 | * |
||
732 | * @param ConnectionInterface $con |
||
733 | * @return int The number of affected rows (if supported by underlying database driver). |
||
734 | */ |
||
735 | protected function doOnDeleteCascade(ConnectionInterface $con) |
||
760 | |||
761 | // i18n behavior |
||
762 | |||
763 | /** |
||
764 | * Adds a JOIN clause to the query using the i18n relation |
||
765 | * |
||
766 | * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' |
||
767 | * @param string $relationAlias optional alias for the relation |
||
768 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. |
||
769 | * |
||
770 | * @return ChildBannersQuery The current query, for fluid interface |
||
771 | */ |
||
772 | View Code Duplication | public function joinI18n($locale = 'ru', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
|
780 | |||
781 | /** |
||
782 | * Adds a JOIN clause to the query and hydrates the related I18n object. |
||
783 | * Shortcut for $c->joinI18n($locale)->with() |
||
784 | * |
||
785 | * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' |
||
786 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. |
||
787 | * |
||
788 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
789 | */ |
||
790 | View Code Duplication | public function joinWithI18n($locale = 'ru', $joinType = Criteria::LEFT_JOIN) |
|
799 | |||
800 | /** |
||
801 | * Use the I18n relation query object |
||
802 | * |
||
803 | * @see useQuery() |
||
804 | * |
||
805 | * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' |
||
806 | * @param string $relationAlias optional alias for the relation |
||
807 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. |
||
808 | * |
||
809 | * @return ChildBannersI18nQuery A secondary query class using the current class as primary query |
||
810 | */ |
||
811 | public function useI18nQuery($locale = 'ru', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
||
817 | |||
818 | } // BannersQuery |
||
819 |