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 | 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) |
|
198 | { |
||
199 | // As the query uses a PK condition, no limit(1) is necessary. |
||
200 | $criteria = $this->isKeepQuery() ? clone $this : $this; |
||
201 | $dataFetcher = $criteria |
||
202 | ->filterByPrimaryKey($key) |
||
203 | ->doSelect($con); |
||
204 | |||
205 | return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher); |
||
206 | } |
||
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) |
|
219 | { |
||
220 | if (null === $con) { |
||
221 | $con = Propel::getServiceContainer()->getReadConnection($this->getDbName()); |
||
222 | } |
||
223 | $this->basePreSelect($con); |
||
224 | $criteria = $this->isKeepQuery() ? clone $this : $this; |
||
225 | $dataFetcher = $criteria |
||
226 | ->filterByPrimaryKeys($keys) |
||
227 | ->doSelect($con); |
||
228 | |||
229 | return $criteria->getFormatter()->init($criteria)->format($dataFetcher); |
||
230 | } |
||
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 | 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%', Criteria::LIKE); // WHERE locale LIKE '%fooValue%' |
||
319 | * </code> |
||
320 | * |
||
321 | * @param string $locale The value to use as filter. |
||
322 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
323 | * |
||
324 | * @return $this|ChildBannersI18nQuery The current query, for fluid interface |
||
325 | */ |
||
326 | View Code Duplication | public function filterByLocale($locale = null, $comparison = null) |
|
336 | |||
337 | /** |
||
338 | * Filter the query on the name column |
||
339 | * |
||
340 | * Example usage: |
||
341 | * <code> |
||
342 | * $query->filterByName('fooValue'); // WHERE name = 'fooValue' |
||
343 | * $query->filterByName('%fooValue%', Criteria::LIKE); // WHERE name LIKE '%fooValue%' |
||
344 | * </code> |
||
345 | * |
||
346 | * @param string $name The value to use as filter. |
||
347 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
348 | * |
||
349 | * @return $this|ChildBannersI18nQuery The current query, for fluid interface |
||
350 | */ |
||
351 | View Code Duplication | public function filterByName($name = null, $comparison = null) |
|
361 | |||
362 | /** |
||
363 | * Filter the query by a related \xbanners\models\Banners object |
||
364 | * |
||
365 | * @param \xbanners\models\Banners|ObjectCollection $banners The related object(s) to use as filter |
||
366 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
367 | * |
||
368 | * @throws \Propel\Runtime\Exception\PropelException |
||
369 | * |
||
370 | * @return ChildBannersI18nQuery The current query, for fluid interface |
||
371 | */ |
||
372 | public function filterByBanners($banners, $comparison = null) |
||
388 | |||
389 | /** |
||
390 | * Adds a JOIN clause to the query using the Banners relation |
||
391 | * |
||
392 | * @param string $relationAlias optional alias for the relation |
||
393 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
394 | * |
||
395 | * @return $this|ChildBannersI18nQuery The current query, for fluid interface |
||
396 | */ |
||
397 | View Code Duplication | public function joinBanners($relationAlias = null, $joinType = 'LEFT JOIN') |
|
420 | |||
421 | /** |
||
422 | * Use the Banners relation Banners object |
||
423 | * |
||
424 | * @see useQuery() |
||
425 | * |
||
426 | * @param string $relationAlias optional alias for the relation, |
||
427 | * to be used as main alias in the secondary query |
||
428 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
429 | * |
||
430 | * @return \xbanners\models\BannersQuery A secondary query class using the current class as primary query |
||
431 | */ |
||
432 | public function useBannersQuery($relationAlias = null, $joinType = 'LEFT JOIN') |
||
438 | |||
439 | /** |
||
440 | * Exclude object from result |
||
441 | * |
||
442 | * @param ChildBannersI18n $bannersI18n Object to remove from the list of results |
||
443 | * |
||
444 | * @return $this|ChildBannersI18nQuery The current query, for fluid interface |
||
445 | */ |
||
446 | public function prune($bannersI18n = null) |
||
456 | |||
457 | /** |
||
458 | * Deletes all rows from the banners_i18n table. |
||
459 | * |
||
460 | * @param ConnectionInterface $con the connection to use |
||
461 | * @return int The number of affected rows (if supported by underlying database driver). |
||
462 | */ |
||
463 | View Code Duplication | public function doDeleteAll(ConnectionInterface $con = null) |
|
483 | |||
484 | /** |
||
485 | * Performs a DELETE on the database based on the current ModelCriteria |
||
486 | * |
||
487 | * @param ConnectionInterface $con the connection to use |
||
488 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
489 | * if supported by native driver or if emulated using Propel. |
||
490 | * @throws PropelException Any exceptions caught during processing will be |
||
491 | * rethrown wrapped into a PropelException. |
||
492 | */ |
||
493 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
517 | |||
518 | } // BannersI18nQuery |
||
519 |