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 | View Code Duplication | public function findPk($key, ConnectionInterface $con = null)  | 
            |
| 175 | |||
| 176 | /**  | 
            ||
| 177 | * Find object by primary key using raw SQL to go fast.  | 
            ||
| 178 | * Bypass doSelect() and the object formatter by using generated code.  | 
            ||
| 179 | *  | 
            ||
| 180 | * @param mixed $key Primary key to use for the query  | 
            ||
| 181 | * @param ConnectionInterface $con A connection object  | 
            ||
| 182 | *  | 
            ||
| 183 | * @throws \Propel\Runtime\Exception\PropelException  | 
            ||
| 184 | *  | 
            ||
| 185 | * @return ChildBanners A model object, or null if the key is not found  | 
            ||
| 186 | */  | 
            ||
| 187 | View Code Duplication | protected function findPkSimple($key, ConnectionInterface $con)  | 
            |
| 209 | |||
| 210 | /**  | 
            ||
| 211 | * Find object by primary key.  | 
            ||
| 212 | *  | 
            ||
| 213 | * @param mixed $key Primary key to use for the query  | 
            ||
| 214 | * @param ConnectionInterface $con A connection object  | 
            ||
| 215 | *  | 
            ||
| 216 | * @return ChildBanners|array|mixed the result, formatted by the current formatter  | 
            ||
| 217 | */  | 
            ||
| 218 | View Code Duplication | protected function findPkComplex($key, ConnectionInterface $con)  | 
            |
| 228 | |||
| 229 | /**  | 
            ||
| 230 | * Find objects by primary key  | 
            ||
| 231 | * <code>  | 
            ||
| 232 | * $objs = $c->findPks(array(12, 56, 832), $con);  | 
            ||
| 233 | * </code>  | 
            ||
| 234 | * @param array $keys Primary keys to use for the query  | 
            ||
| 235 | * @param ConnectionInterface $con an optional connection object  | 
            ||
| 236 | *  | 
            ||
| 237 | * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter  | 
            ||
| 238 | */  | 
            ||
| 239 | View Code Duplication | public function findPks($keys, ConnectionInterface $con = null)  | 
            |
| 252 | |||
| 253 | /**  | 
            ||
| 254 | * Filter the query by primary key  | 
            ||
| 255 | *  | 
            ||
| 256 | * @param mixed $key Primary key to use for the query  | 
            ||
| 257 | *  | 
            ||
| 258 | * @return $this|ChildBannersQuery The current query, for fluid interface  | 
            ||
| 259 | */  | 
            ||
| 260 | public function filterByPrimaryKey($key)  | 
            ||
| 265 | |||
| 266 | /**  | 
            ||
| 267 | * Filter the query by a list of primary keys  | 
            ||
| 268 | *  | 
            ||
| 269 | * @param array $keys The list of primary key to use for the query  | 
            ||
| 270 | *  | 
            ||
| 271 | * @return $this|ChildBannersQuery The current query, for fluid interface  | 
            ||
| 272 | */  | 
            ||
| 273 | public function filterByPrimaryKeys($keys)  | 
            ||
| 278 | |||
| 279 | /**  | 
            ||
| 280 | * Filter the query on the id column  | 
            ||
| 281 | *  | 
            ||
| 282 | * Example usage:  | 
            ||
| 283 | * <code>  | 
            ||
| 284 | * $query->filterById(1234); // WHERE id = 1234  | 
            ||
| 285 | * $query->filterById(array(12, 34)); // WHERE id IN (12, 34)  | 
            ||
| 286 |      * $query->filterById(array('min' => 12)); // WHERE id > 12 | 
            ||
| 287 | * </code>  | 
            ||
| 288 | *  | 
            ||
| 289 | * @param mixed $id The value to use as filter.  | 
            ||
| 290 | * Use scalar values for equality.  | 
            ||
| 291 | * Use array values for in_array() equivalent.  | 
            ||
| 292 |      *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. | 
            ||
| 293 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL  | 
            ||
| 294 | *  | 
            ||
| 295 | * @return $this|ChildBannersQuery The current query, for fluid interface  | 
            ||
| 296 | */  | 
            ||
| 297 | View Code Duplication | public function filterById($id = null, $comparison = null)  | 
            |
| 319 | |||
| 320 | /**  | 
            ||
| 321 | * Filter the query on the place column  | 
            ||
| 322 | *  | 
            ||
| 323 | * Example usage:  | 
            ||
| 324 | * <code>  | 
            ||
| 325 |      * $query->filterByPlace('fooValue');   // WHERE place = 'fooValue' | 
            ||
| 326 |      * $query->filterByPlace('%fooValue%'); // WHERE place LIKE '%fooValue%' | 
            ||
| 327 | * </code>  | 
            ||
| 328 | *  | 
            ||
| 329 | * @param string $place The value to use as filter.  | 
            ||
| 330 | * Accepts wildcards (* and % trigger a LIKE)  | 
            ||
| 331 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL  | 
            ||
| 332 | *  | 
            ||
| 333 | * @return $this|ChildBannersQuery The current query, for fluid interface  | 
            ||
| 334 | */  | 
            ||
| 335 | View Code Duplication | public function filterByPlace($place = null, $comparison = null)  | 
            |
| 348 | |||
| 349 | /**  | 
            ||
| 350 | * Filter the query on the width column  | 
            ||
| 351 | *  | 
            ||
| 352 | * Example usage:  | 
            ||
| 353 | * <code>  | 
            ||
| 354 | * $query->filterByWidth(1234); // WHERE width = 1234  | 
            ||
| 355 | * $query->filterByWidth(array(12, 34)); // WHERE width IN (12, 34)  | 
            ||
| 356 |      * $query->filterByWidth(array('min' => 12)); // WHERE width > 12 | 
            ||
| 357 | * </code>  | 
            ||
| 358 | *  | 
            ||
| 359 | * @param mixed $width The value to use as filter.  | 
            ||
| 360 | * Use scalar values for equality.  | 
            ||
| 361 | * Use array values for in_array() equivalent.  | 
            ||
| 362 |      *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. | 
            ||
| 363 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL  | 
            ||
| 364 | *  | 
            ||
| 365 | * @return $this|ChildBannersQuery The current query, for fluid interface  | 
            ||
| 366 | */  | 
            ||
| 367 | View Code Duplication | public function filterByWidth($width = null, $comparison = null)  | 
            |
| 389 | |||
| 390 | /**  | 
            ||
| 391 | * Filter the query on the height column  | 
            ||
| 392 | *  | 
            ||
| 393 | * Example usage:  | 
            ||
| 394 | * <code>  | 
            ||
| 395 | * $query->filterByHeight(1234); // WHERE height = 1234  | 
            ||
| 396 | * $query->filterByHeight(array(12, 34)); // WHERE height IN (12, 34)  | 
            ||
| 397 |      * $query->filterByHeight(array('min' => 12)); // WHERE height > 12 | 
            ||
| 398 | * </code>  | 
            ||
| 399 | *  | 
            ||
| 400 | * @param mixed $height The value to use as filter.  | 
            ||
| 401 | * Use scalar values for equality.  | 
            ||
| 402 | * Use array values for in_array() equivalent.  | 
            ||
| 403 |      *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. | 
            ||
| 404 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL  | 
            ||
| 405 | *  | 
            ||
| 406 | * @return $this|ChildBannersQuery The current query, for fluid interface  | 
            ||
| 407 | */  | 
            ||
| 408 | View Code Duplication | public function filterByHeight($height = null, $comparison = null)  | 
            |
| 430 | |||
| 431 | /**  | 
            ||
| 432 | * Filter the query on the effects column  | 
            ||
| 433 | *  | 
            ||
| 434 | * Example usage:  | 
            ||
| 435 | * <code>  | 
            ||
| 436 |      * $query->filterByEffects('fooValue');   // WHERE effects = 'fooValue' | 
            ||
| 437 |      * $query->filterByEffects('%fooValue%'); // WHERE effects LIKE '%fooValue%' | 
            ||
| 438 | * </code>  | 
            ||
| 439 | *  | 
            ||
| 440 | * @param string $effects The value to use as filter.  | 
            ||
| 441 | * Accepts wildcards (* and % trigger a LIKE)  | 
            ||
| 442 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL  | 
            ||
| 443 | *  | 
            ||
| 444 | * @return $this|ChildBannersQuery The current query, for fluid interface  | 
            ||
| 445 | */  | 
            ||
| 446 | View Code Duplication | public function filterByEffects($effects = null, $comparison = null)  | 
            |
| 459 | |||
| 460 | /**  | 
            ||
| 461 | * Filter the query on the page_type column  | 
            ||
| 462 | *  | 
            ||
| 463 | * Example usage:  | 
            ||
| 464 | * <code>  | 
            ||
| 465 |      * $query->filterByPageType('fooValue');   // WHERE page_type = 'fooValue' | 
            ||
| 466 |      * $query->filterByPageType('%fooValue%'); // WHERE page_type LIKE '%fooValue%' | 
            ||
| 467 | * </code>  | 
            ||
| 468 | *  | 
            ||
| 469 | * @param string $pageType The value to use as filter.  | 
            ||
| 470 | * Accepts wildcards (* and % trigger a LIKE)  | 
            ||
| 471 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL  | 
            ||
| 472 | *  | 
            ||
| 473 | * @return $this|ChildBannersQuery The current query, for fluid interface  | 
            ||
| 474 | */  | 
            ||
| 475 | View Code Duplication | public function filterByPageType($pageType = null, $comparison = null)  | 
            |
| 488 | |||
| 489 | /**  | 
            ||
| 490 | * Filter the query by a related \xbanners\models\BannerImage object  | 
            ||
| 491 | *  | 
            ||
| 492 | * @param \xbanners\models\BannerImage|ObjectCollection $bannerImage the related object to use as filter  | 
            ||
| 493 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL  | 
            ||
| 494 | *  | 
            ||
| 495 | * @return ChildBannersQuery The current query, for fluid interface  | 
            ||
| 496 | */  | 
            ||
| 497 | View Code Duplication | public function filterByBannerImage($bannerImage, $comparison = null)  | 
            |
| 511 | |||
| 512 | /**  | 
            ||
| 513 | * Adds a JOIN clause to the query using the BannerImage relation  | 
            ||
| 514 | *  | 
            ||
| 515 | * @param string $relationAlias optional alias for the relation  | 
            ||
| 516 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'  | 
            ||
| 517 | *  | 
            ||
| 518 | * @return $this|ChildBannersQuery The current query, for fluid interface  | 
            ||
| 519 | */  | 
            ||
| 520 | View Code Duplication | public function joinBannerImage($relationAlias = null, $joinType = Criteria::INNER_JOIN)  | 
            |
| 543 | |||
| 544 | /**  | 
            ||
| 545 | * Use the BannerImage relation BannerImage object  | 
            ||
| 546 | *  | 
            ||
| 547 | * @see useQuery()  | 
            ||
| 548 | *  | 
            ||
| 549 | * @param string $relationAlias optional alias for the relation,  | 
            ||
| 550 | * to be used as main alias in the secondary query  | 
            ||
| 551 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'  | 
            ||
| 552 | *  | 
            ||
| 553 | * @return \xbanners\models\BannerImageQuery A secondary query class using the current class as primary query  | 
            ||
| 554 | */  | 
            ||
| 555 | public function useBannerImageQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)  | 
            ||
| 561 | |||
| 562 | /**  | 
            ||
| 563 | * Filter the query by a related \xbanners\models\BannersI18n object  | 
            ||
| 564 | *  | 
            ||
| 565 | * @param \xbanners\models\BannersI18n|ObjectCollection $bannersI18n the related object to use as filter  | 
            ||
| 566 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL  | 
            ||
| 567 | *  | 
            ||
| 568 | * @return ChildBannersQuery The current query, for fluid interface  | 
            ||
| 569 | */  | 
            ||
| 570 | View Code Duplication | public function filterByBannersI18n($bannersI18n, $comparison = null)  | 
            |
| 584 | |||
| 585 | /**  | 
            ||
| 586 | * Adds a JOIN clause to the query using the BannersI18n relation  | 
            ||
| 587 | *  | 
            ||
| 588 | * @param string $relationAlias optional alias for the relation  | 
            ||
| 589 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'  | 
            ||
| 590 | *  | 
            ||
| 591 | * @return $this|ChildBannersQuery The current query, for fluid interface  | 
            ||
| 592 | */  | 
            ||
| 593 | View Code Duplication | public function joinBannersI18n($relationAlias = null, $joinType = 'LEFT JOIN')  | 
            |
| 616 | |||
| 617 | /**  | 
            ||
| 618 | * Use the BannersI18n relation BannersI18n object  | 
            ||
| 619 | *  | 
            ||
| 620 | * @see useQuery()  | 
            ||
| 621 | *  | 
            ||
| 622 | * @param string $relationAlias optional alias for the relation,  | 
            ||
| 623 | * to be used as main alias in the secondary query  | 
            ||
| 624 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'  | 
            ||
| 625 | *  | 
            ||
| 626 | * @return \xbanners\models\BannersI18nQuery A secondary query class using the current class as primary query  | 
            ||
| 627 | */  | 
            ||
| 628 | public function useBannersI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN')  | 
            ||
| 634 | |||
| 635 | /**  | 
            ||
| 636 | * Exclude object from result  | 
            ||
| 637 | *  | 
            ||
| 638 | * @param ChildBanners $banners Object to remove from the list of results  | 
            ||
| 639 | *  | 
            ||
| 640 | * @return $this|ChildBannersQuery The current query, for fluid interface  | 
            ||
| 641 | */  | 
            ||
| 642 | public function prune($banners = null)  | 
            ||
| 650 | |||
| 651 | /**  | 
            ||
| 652 | * Deletes all rows from the banners table.  | 
            ||
| 653 | *  | 
            ||
| 654 | * @param ConnectionInterface $con the connection to use  | 
            ||
| 655 | * @return int The number of affected rows (if supported by underlying database driver).  | 
            ||
| 656 | */  | 
            ||
| 657 | View Code Duplication | public function doDeleteAll(ConnectionInterface $con = null)  | 
            |
| 678 | |||
| 679 | /**  | 
            ||
| 680 | * Performs a DELETE on the database based on the current ModelCriteria  | 
            ||
| 681 | *  | 
            ||
| 682 | * @param ConnectionInterface $con the connection to use  | 
            ||
| 683 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows  | 
            ||
| 684 | * if supported by native driver or if emulated using Propel.  | 
            ||
| 685 | * @throws PropelException Any exceptions caught during processing will be  | 
            ||
| 686 | * rethrown wrapped into a PropelException.  | 
            ||
| 687 | */  | 
            ||
| 688 | View Code Duplication | public function delete(ConnectionInterface $con = null)  | 
            |
| 716 | |||
| 717 | /**  | 
            ||
| 718 | * This is a method for emulating ON DELETE CASCADE for DBs that don't support this  | 
            ||
| 719 | * feature (like MySQL or SQLite).  | 
            ||
| 720 | *  | 
            ||
| 721 | * This method is not very speedy because it must perform a query first to get  | 
            ||
| 722 | * the implicated records and then perform the deletes by calling those Query classes.  | 
            ||
| 723 | *  | 
            ||
| 724 | * This method should be used within a transaction if possible.  | 
            ||
| 725 | *  | 
            ||
| 726 | * @param ConnectionInterface $con  | 
            ||
| 727 | * @return int The number of affected rows (if supported by underlying database driver).  | 
            ||
| 728 | */  | 
            ||
| 729 | protected function doOnDeleteCascade(ConnectionInterface $con)  | 
            ||
| 754 | |||
| 755 | // i18n behavior  | 
            ||
| 756 | |||
| 757 | /**  | 
            ||
| 758 | * Adds a JOIN clause to the query using the i18n relation  | 
            ||
| 759 | *  | 
            ||
| 760 | * @param string $locale Locale to use for the join condition, e.g. 'fr_FR'  | 
            ||
| 761 | * @param string $relationAlias optional alias for the relation  | 
            ||
| 762 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.  | 
            ||
| 763 | *  | 
            ||
| 764 | * @return ChildBannersQuery The current query, for fluid interface  | 
            ||
| 765 | */  | 
            ||
| 766 | View Code Duplication | public function joinI18n($locale = 'ru', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)  | 
            |
| 774 | |||
| 775 | /**  | 
            ||
| 776 | * Adds a JOIN clause to the query and hydrates the related I18n object.  | 
            ||
| 777 | * Shortcut for $c->joinI18n($locale)->with()  | 
            ||
| 778 | *  | 
            ||
| 779 | * @param string $locale Locale to use for the join condition, e.g. 'fr_FR'  | 
            ||
| 780 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.  | 
            ||
| 781 | *  | 
            ||
| 782 | * @return $this|ChildBannersQuery The current query, for fluid interface  | 
            ||
| 783 | */  | 
            ||
| 784 | View Code Duplication | public function joinWithI18n($locale = 'ru', $joinType = Criteria::LEFT_JOIN)  | 
            |
| 793 | |||
| 794 | /**  | 
            ||
| 795 | * Use the I18n relation query object  | 
            ||
| 796 | *  | 
            ||
| 797 | * @see useQuery()  | 
            ||
| 798 | *  | 
            ||
| 799 | * @param string $locale Locale to use for the join condition, e.g. 'fr_FR'  | 
            ||
| 800 | * @param string $relationAlias optional alias for the relation  | 
            ||
| 801 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join.  | 
            ||
| 802 | *  | 
            ||
| 803 | * @return ChildBannersI18nQuery A secondary query class using the current class as primary query  | 
            ||
| 804 | */  | 
            ||
| 805 | public function useI18nQuery($locale = 'ru', $relationAlias = null, $joinType = Criteria::LEFT_JOIN)  | 
            ||
| 811 | |||
| 812 | } // BannersQuery  | 
            ||
| 813 |