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 BannersI18nQuery 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 BannersI18nQuery, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 72 | abstract class BannersI18nQuery extends ModelCriteria |
||
| 73 | { |
||
| 74 | protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException'; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Initializes internal state of \xbanners\models\Base\BannersI18nQuery object. |
||
| 78 | * |
||
| 79 | * @param string $dbName The database name |
||
| 80 | * @param string $modelName The phpName of a model, e.g. 'Book' |
||
| 81 | * @param string $modelAlias The alias for the model in this query, e.g. 'b' |
||
| 82 | */ |
||
| 83 | public function __construct($dbName = 'Shop', $modelName = '\\xbanners\\models\\BannersI18n', $modelAlias = null) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Returns a new ChildBannersI18nQuery object. |
||
| 90 | * |
||
| 91 | * @param string $modelAlias The alias of a model in the query |
||
| 92 | * @param Criteria $criteria Optional Criteria to build the query from |
||
| 93 | * |
||
| 94 | * @return ChildBannersI18nQuery |
||
| 95 | */ |
||
| 96 | View Code Duplication | public static function create($modelAlias = null, Criteria $criteria = null) |
|
| 111 | |||
| 112 | /** |
||
| 113 | * Find object by primary key. |
||
| 114 | * Propel uses the instance pool to skip the database if the object exists. |
||
| 115 | * Go fast if the query is untouched. |
||
| 116 | * |
||
| 117 | * <code> |
||
| 118 | * $obj = $c->findPk(array(12, 34), $con); |
||
| 119 | * </code> |
||
| 120 | * |
||
| 121 | * @param array[$id, $locale] $key Primary key to use for the query |
||
| 122 | * @param ConnectionInterface $con an optional connection object |
||
| 123 | * |
||
| 124 | * @return ChildBannersI18n|array|mixed the result, formatted by the current formatter |
||
| 125 | */ |
||
| 126 | public function findPk($key, ConnectionInterface $con = null) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Find object by primary key using raw SQL to go fast. |
||
| 156 | * Bypass doSelect() and the object formatter by using generated code. |
||
| 157 | * |
||
| 158 | * @param mixed $key Primary key to use for the query |
||
| 159 | * @param ConnectionInterface $con A connection object |
||
| 160 | * |
||
| 161 | * @throws \Propel\Runtime\Exception\PropelException |
||
| 162 | * |
||
| 163 | * @return ChildBannersI18n A model object, or null if the key is not found |
||
| 164 | */ |
||
| 165 | View Code Duplication | protected function findPkSimple($key, ConnectionInterface $con) |
|
| 188 | |||
| 189 | /** |
||
| 190 | * Find object by primary key. |
||
| 191 | * |
||
| 192 | * @param mixed $key Primary key to use for the query |
||
| 193 | * @param ConnectionInterface $con A connection object |
||
| 194 | * |
||
| 195 | * @return ChildBannersI18n|array|mixed the result, formatted by the current formatter |
||
| 196 | */ |
||
| 197 | View Code Duplication | protected function findPkComplex($key, ConnectionInterface $con) |
|
| 207 | |||
| 208 | /** |
||
| 209 | * Find objects by primary key |
||
| 210 | * <code> |
||
| 211 | * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con); |
||
| 212 | * </code> |
||
| 213 | * @param array $keys Primary keys to use for the query |
||
| 214 | * @param ConnectionInterface $con an optional connection object |
||
| 215 | * |
||
| 216 | * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter |
||
| 217 | */ |
||
| 218 | View Code Duplication | public function findPks($keys, ConnectionInterface $con = null) |
|
| 231 | |||
| 232 | /** |
||
| 233 | * Filter the query by primary key |
||
| 234 | * |
||
| 235 | * @param mixed $key Primary key to use for the query |
||
| 236 | * |
||
| 237 | * @return $this|ChildBannersI18nQuery The current query, for fluid interface |
||
| 238 | */ |
||
| 239 | public function filterByPrimaryKey($key) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Filter the query by a list of primary keys |
||
| 249 | * |
||
| 250 | * @param array $keys The list of primary key to use for the query |
||
| 251 | * |
||
| 252 | * @return $this|ChildBannersI18nQuery The current query, for fluid interface |
||
| 253 | */ |
||
| 254 | View Code Duplication | public function filterByPrimaryKeys($keys) |
|
| 268 | |||
| 269 | /** |
||
| 270 | * Filter the query on the id column |
||
| 271 | * |
||
| 272 | * Example usage: |
||
| 273 | * <code> |
||
| 274 | * $query->filterById(1234); // WHERE id = 1234 |
||
| 275 | * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) |
||
| 276 | * $query->filterById(array('min' => 12)); // WHERE id > 12 |
||
| 277 | * </code> |
||
| 278 | * |
||
| 279 | * @see filterByBanners() |
||
| 280 | * |
||
| 281 | * @param mixed $id The value to use as filter. |
||
| 282 | * Use scalar values for equality. |
||
| 283 | * Use array values for in_array() equivalent. |
||
| 284 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
| 285 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 286 | * |
||
| 287 | * @return $this|ChildBannersI18nQuery The current query, for fluid interface |
||
| 288 | */ |
||
| 289 | View Code Duplication | public function filterById($id = null, $comparison = null) |
|
| 311 | |||
| 312 | /** |
||
| 313 | * Filter the query on the locale column |
||
| 314 | * |
||
| 315 | * Example usage: |
||
| 316 | * <code> |
||
| 317 | * $query->filterByLocale('fooValue'); // WHERE locale = 'fooValue' |
||
| 318 | * $query->filterByLocale('%fooValue%'); // WHERE locale LIKE '%fooValue%' |
||
| 319 | * </code> |
||
| 320 | * |
||
| 321 | * @param string $locale The value to use as filter. |
||
| 322 | * Accepts wildcards (* and % trigger a LIKE) |
||
| 323 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 324 | * |
||
| 325 | * @return $this|ChildBannersI18nQuery The current query, for fluid interface |
||
| 326 | */ |
||
| 327 | View Code Duplication | public function filterByLocale($locale = null, $comparison = null) |
|
| 340 | |||
| 341 | /** |
||
| 342 | * Filter the query on the name column |
||
| 343 | * |
||
| 344 | * Example usage: |
||
| 345 | * <code> |
||
| 346 | * $query->filterByName('fooValue'); // WHERE name = 'fooValue' |
||
| 347 | * $query->filterByName('%fooValue%'); // WHERE name LIKE '%fooValue%' |
||
| 348 | * </code> |
||
| 349 | * |
||
| 350 | * @param string $name The value to use as filter. |
||
| 351 | * Accepts wildcards (* and % trigger a LIKE) |
||
| 352 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 353 | * |
||
| 354 | * @return $this|ChildBannersI18nQuery The current query, for fluid interface |
||
| 355 | */ |
||
| 356 | View Code Duplication | public function filterByName($name = null, $comparison = null) |
|
| 369 | |||
| 370 | /** |
||
| 371 | * Filter the query by a related \xbanners\models\Banners object |
||
| 372 | * |
||
| 373 | * @param \xbanners\models\Banners|ObjectCollection $banners The related object(s) to use as filter |
||
| 374 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 375 | * |
||
| 376 | * @throws \Propel\Runtime\Exception\PropelException |
||
| 377 | * |
||
| 378 | * @return ChildBannersI18nQuery The current query, for fluid interface |
||
| 379 | */ |
||
| 380 | View Code Duplication | public function filterByBanners($banners, $comparison = null) |
|
| 396 | |||
| 397 | /** |
||
| 398 | * Adds a JOIN clause to the query using the Banners relation |
||
| 399 | * |
||
| 400 | * @param string $relationAlias optional alias for the relation |
||
| 401 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
| 402 | * |
||
| 403 | * @return $this|ChildBannersI18nQuery The current query, for fluid interface |
||
| 404 | */ |
||
| 405 | View Code Duplication | public function joinBanners($relationAlias = null, $joinType = 'LEFT JOIN') |
|
| 428 | |||
| 429 | /** |
||
| 430 | * Use the Banners relation Banners object |
||
| 431 | * |
||
| 432 | * @see useQuery() |
||
| 433 | * |
||
| 434 | * @param string $relationAlias optional alias for the relation, |
||
| 435 | * to be used as main alias in the secondary query |
||
| 436 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
| 437 | * |
||
| 438 | * @return \xbanners\models\BannersQuery A secondary query class using the current class as primary query |
||
| 439 | */ |
||
| 440 | public function useBannersQuery($relationAlias = null, $joinType = 'LEFT JOIN') |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Exclude object from result |
||
| 449 | * |
||
| 450 | * @param ChildBannersI18n $bannersI18n Object to remove from the list of results |
||
| 451 | * |
||
| 452 | * @return $this|ChildBannersI18nQuery The current query, for fluid interface |
||
| 453 | */ |
||
| 454 | View Code Duplication | public function prune($bannersI18n = null) |
|
| 464 | |||
| 465 | /** |
||
| 466 | * Deletes all rows from the banners_i18n table. |
||
| 467 | * |
||
| 468 | * @param ConnectionInterface $con the connection to use |
||
| 469 | * @return int The number of affected rows (if supported by underlying database driver). |
||
| 470 | */ |
||
| 471 | public function doDeleteAll(ConnectionInterface $con = null) |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Performs a DELETE on the database based on the current ModelCriteria |
||
| 494 | * |
||
| 495 | * @param ConnectionInterface $con the connection to use |
||
| 496 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
| 497 | * if supported by native driver or if emulated using Propel. |
||
| 498 | * @throws PropelException Any exceptions caught during processing will be |
||
| 499 | * rethrown wrapped into a PropelException. |
||
| 500 | */ |
||
| 501 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
| 525 | |||
| 526 | } // BannersI18nQuery |
||
| 527 |