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) |
|
| 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%', Criteria::LIKE); // WHERE place LIKE '%fooValue%' |
||
| 333 | * </code> |
||
| 334 | * |
||
| 335 | * @param string $place The value to use as filter. |
||
| 336 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 337 | * |
||
| 338 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
| 339 | */ |
||
| 340 | View Code Duplication | public function filterByPlace($place = null, $comparison = null) |
|
| 350 | |||
| 351 | /** |
||
| 352 | * Filter the query on the width column |
||
| 353 | * |
||
| 354 | * Example usage: |
||
| 355 | * <code> |
||
| 356 | * $query->filterByWidth(1234); // WHERE width = 1234 |
||
| 357 | * $query->filterByWidth(array(12, 34)); // WHERE width IN (12, 34) |
||
| 358 | * $query->filterByWidth(array('min' => 12)); // WHERE width > 12 |
||
| 359 | * </code> |
||
| 360 | * |
||
| 361 | * @param mixed $width The value to use as filter. |
||
| 362 | * Use scalar values for equality. |
||
| 363 | * Use array values for in_array() equivalent. |
||
| 364 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
| 365 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 366 | * |
||
| 367 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
| 368 | */ |
||
| 369 | View Code Duplication | public function filterByWidth($width = null, $comparison = null) |
|
| 391 | |||
| 392 | /** |
||
| 393 | * Filter the query on the height column |
||
| 394 | * |
||
| 395 | * Example usage: |
||
| 396 | * <code> |
||
| 397 | * $query->filterByHeight(1234); // WHERE height = 1234 |
||
| 398 | * $query->filterByHeight(array(12, 34)); // WHERE height IN (12, 34) |
||
| 399 | * $query->filterByHeight(array('min' => 12)); // WHERE height > 12 |
||
| 400 | * </code> |
||
| 401 | * |
||
| 402 | * @param mixed $height The value to use as filter. |
||
| 403 | * Use scalar values for equality. |
||
| 404 | * Use array values for in_array() equivalent. |
||
| 405 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
| 406 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 407 | * |
||
| 408 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
| 409 | */ |
||
| 410 | View Code Duplication | public function filterByHeight($height = null, $comparison = null) |
|
| 432 | |||
| 433 | /** |
||
| 434 | * Filter the query on the effects column |
||
| 435 | * |
||
| 436 | * Example usage: |
||
| 437 | * <code> |
||
| 438 | * $query->filterByEffects('fooValue'); // WHERE effects = 'fooValue' |
||
| 439 | * $query->filterByEffects('%fooValue%', Criteria::LIKE); // WHERE effects LIKE '%fooValue%' |
||
| 440 | * </code> |
||
| 441 | * |
||
| 442 | * @param string $effects The value to use as filter. |
||
| 443 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 444 | * |
||
| 445 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
| 446 | */ |
||
| 447 | View Code Duplication | public function filterByEffects($effects = null, $comparison = null) |
|
| 457 | |||
| 458 | /** |
||
| 459 | * Filter the query on the page_type column |
||
| 460 | * |
||
| 461 | * Example usage: |
||
| 462 | * <code> |
||
| 463 | * $query->filterByPageType('fooValue'); // WHERE page_type = 'fooValue' |
||
| 464 | * $query->filterByPageType('%fooValue%', Criteria::LIKE); // WHERE page_type LIKE '%fooValue%' |
||
| 465 | * </code> |
||
| 466 | * |
||
| 467 | * @param string $pageType The value to use as filter. |
||
| 468 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 469 | * |
||
| 470 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
| 471 | */ |
||
| 472 | View Code Duplication | public function filterByPageType($pageType = null, $comparison = null) |
|
| 482 | |||
| 483 | /** |
||
| 484 | * Filter the query by a related \xbanners\models\BannerImage object |
||
| 485 | * |
||
| 486 | * @param \xbanners\models\BannerImage|ObjectCollection $bannerImage the related object to use as filter |
||
| 487 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 488 | * |
||
| 489 | * @return ChildBannersQuery The current query, for fluid interface |
||
| 490 | */ |
||
| 491 | View Code Duplication | public function filterByBannerImage($bannerImage, $comparison = null) |
|
| 505 | |||
| 506 | /** |
||
| 507 | * Adds a JOIN clause to the query using the BannerImage relation |
||
| 508 | * |
||
| 509 | * @param string $relationAlias optional alias for the relation |
||
| 510 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
| 511 | * |
||
| 512 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
| 513 | */ |
||
| 514 | View Code Duplication | public function joinBannerImage($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
|
| 537 | |||
| 538 | /** |
||
| 539 | * Use the BannerImage relation BannerImage object |
||
| 540 | * |
||
| 541 | * @see useQuery() |
||
| 542 | * |
||
| 543 | * @param string $relationAlias optional alias for the relation, |
||
| 544 | * to be used as main alias in the secondary query |
||
| 545 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
| 546 | * |
||
| 547 | * @return \xbanners\models\BannerImageQuery A secondary query class using the current class as primary query |
||
| 548 | */ |
||
| 549 | public function useBannerImageQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
||
| 555 | |||
| 556 | /** |
||
| 557 | * Filter the query by a related \xbanners\models\BannersI18n object |
||
| 558 | * |
||
| 559 | * @param \xbanners\models\BannersI18n|ObjectCollection $bannersI18n the related object to use as filter |
||
| 560 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 561 | * |
||
| 562 | * @return ChildBannersQuery The current query, for fluid interface |
||
| 563 | */ |
||
| 564 | View Code Duplication | public function filterByBannersI18n($bannersI18n, $comparison = null) |
|
| 578 | |||
| 579 | /** |
||
| 580 | * Adds a JOIN clause to the query using the BannersI18n relation |
||
| 581 | * |
||
| 582 | * @param string $relationAlias optional alias for the relation |
||
| 583 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
| 584 | * |
||
| 585 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
| 586 | */ |
||
| 587 | View Code Duplication | public function joinBannersI18n($relationAlias = null, $joinType = 'LEFT JOIN') |
|
| 610 | |||
| 611 | /** |
||
| 612 | * Use the BannersI18n relation BannersI18n object |
||
| 613 | * |
||
| 614 | * @see useQuery() |
||
| 615 | * |
||
| 616 | * @param string $relationAlias optional alias for the relation, |
||
| 617 | * to be used as main alias in the secondary query |
||
| 618 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
| 619 | * |
||
| 620 | * @return \xbanners\models\BannersI18nQuery A secondary query class using the current class as primary query |
||
| 621 | */ |
||
| 622 | public function useBannersI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN') |
||
| 628 | |||
| 629 | /** |
||
| 630 | * Exclude object from result |
||
| 631 | * |
||
| 632 | * @param ChildBanners $banners Object to remove from the list of results |
||
| 633 | * |
||
| 634 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
| 635 | */ |
||
| 636 | public function prune($banners = null) |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Deletes all rows from the banners table. |
||
| 647 | * |
||
| 648 | * @param ConnectionInterface $con the connection to use |
||
| 649 | * @return int The number of affected rows (if supported by underlying database driver). |
||
| 650 | */ |
||
| 651 | View Code Duplication | public function doDeleteAll(ConnectionInterface $con = null) |
|
| 672 | |||
| 673 | /** |
||
| 674 | * Performs a DELETE on the database based on the current ModelCriteria |
||
| 675 | * |
||
| 676 | * @param ConnectionInterface $con the connection to use |
||
| 677 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
| 678 | * if supported by native driver or if emulated using Propel. |
||
| 679 | * @throws PropelException Any exceptions caught during processing will be |
||
| 680 | * rethrown wrapped into a PropelException. |
||
| 681 | */ |
||
| 682 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
| 710 | |||
| 711 | /** |
||
| 712 | * This is a method for emulating ON DELETE CASCADE for DBs that don't support this |
||
| 713 | * feature (like MySQL or SQLite). |
||
| 714 | * |
||
| 715 | * This method is not very speedy because it must perform a query first to get |
||
| 716 | * the implicated records and then perform the deletes by calling those Query classes. |
||
| 717 | * |
||
| 718 | * This method should be used within a transaction if possible. |
||
| 719 | * |
||
| 720 | * @param ConnectionInterface $con |
||
| 721 | * @return int The number of affected rows (if supported by underlying database driver). |
||
| 722 | */ |
||
| 723 | protected function doOnDeleteCascade(ConnectionInterface $con) |
||
| 748 | |||
| 749 | // i18n behavior |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Adds a JOIN clause to the query using the i18n relation |
||
| 753 | * |
||
| 754 | * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' |
||
| 755 | * @param string $relationAlias optional alias for the relation |
||
| 756 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. |
||
| 757 | * |
||
| 758 | * @return ChildBannersQuery The current query, for fluid interface |
||
| 759 | */ |
||
| 760 | View Code Duplication | public function joinI18n($locale = 'ru', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
|
| 768 | |||
| 769 | /** |
||
| 770 | * Adds a JOIN clause to the query and hydrates the related I18n object. |
||
| 771 | * Shortcut for $c->joinI18n($locale)->with() |
||
| 772 | * |
||
| 773 | * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' |
||
| 774 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. |
||
| 775 | * |
||
| 776 | * @return $this|ChildBannersQuery The current query, for fluid interface |
||
| 777 | */ |
||
| 778 | View Code Duplication | public function joinWithI18n($locale = 'ru', $joinType = Criteria::LEFT_JOIN) |
|
| 787 | |||
| 788 | /** |
||
| 789 | * Use the I18n relation query object |
||
| 790 | * |
||
| 791 | * @see useQuery() |
||
| 792 | * |
||
| 793 | * @param string $locale Locale to use for the join condition, e.g. 'fr_FR' |
||
| 794 | * @param string $relationAlias optional alias for the relation |
||
| 795 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'. Defaults to left join. |
||
| 796 | * |
||
| 797 | * @return ChildBannersI18nQuery A secondary query class using the current class as primary query |
||
| 798 | */ |
||
| 799 | public function useI18nQuery($locale = 'ru', $relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
||
| 805 | |||
| 806 | } // BannersQuery |
||
| 807 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.