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 PageLinkQuery 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 PageLinkQuery, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
87 | abstract class PageLinkQuery extends ModelCriteria |
||
88 | { |
||
89 | protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException'; |
||
90 | |||
91 | /** |
||
92 | * Initializes internal state of \mod_link\models\Base\PageLinkQuery object. |
||
93 | * |
||
94 | * @param string $dbName The database name |
||
95 | * @param string $modelName The phpName of a model, e.g. 'Book' |
||
96 | * @param string $modelAlias The alias for the model in this query, e.g. 'b' |
||
97 | */ |
||
98 | public function __construct($dbName = 'Shop', $modelName = '\\mod_link\\models\\PageLink', $modelAlias = null) |
||
102 | |||
103 | /** |
||
104 | * Returns a new ChildPageLinkQuery object. |
||
105 | * |
||
106 | * @param string $modelAlias The alias of a model in the query |
||
107 | * @param Criteria $criteria Optional Criteria to build the query from |
||
108 | * |
||
109 | * @return ChildPageLinkQuery |
||
110 | */ |
||
111 | public static function create($modelAlias = null, Criteria $criteria = null) |
||
126 | |||
127 | /** |
||
128 | * Find object by primary key. |
||
129 | * Propel uses the instance pool to skip the database if the object exists. |
||
130 | * Go fast if the query is untouched. |
||
131 | * |
||
132 | * <code> |
||
133 | * $obj = $c->findPk(12, $con); |
||
134 | * </code> |
||
135 | * |
||
136 | * @param mixed $key Primary key to use for the query |
||
137 | * @param ConnectionInterface $con an optional connection object |
||
138 | * |
||
139 | * @return ChildPageLink|array|mixed the result, formatted by the current formatter |
||
140 | */ |
||
141 | View Code Duplication | public function findPk($key, ConnectionInterface $con = null) |
|
168 | |||
169 | /** |
||
170 | * Find object by primary key using raw SQL to go fast. |
||
171 | * Bypass doSelect() and the object formatter by using generated code. |
||
172 | * |
||
173 | * @param mixed $key Primary key to use for the query |
||
174 | * @param ConnectionInterface $con A connection object |
||
175 | * |
||
176 | * @throws \Propel\Runtime\Exception\PropelException |
||
177 | * |
||
178 | * @return ChildPageLink A model object, or null if the key is not found |
||
179 | */ |
||
180 | protected function findPkSimple($key, ConnectionInterface $con) |
||
202 | |||
203 | /** |
||
204 | * Find object by primary key. |
||
205 | * |
||
206 | * @param mixed $key Primary key to use for the query |
||
207 | * @param ConnectionInterface $con A connection object |
||
208 | * |
||
209 | * @return ChildPageLink|array|mixed the result, formatted by the current formatter |
||
210 | */ |
||
211 | protected function findPkComplex($key, ConnectionInterface $con) |
||
221 | |||
222 | /** |
||
223 | * Find objects by primary key |
||
224 | * <code> |
||
225 | * $objs = $c->findPks(array(12, 56, 832), $con); |
||
226 | * </code> |
||
227 | * @param array $keys Primary keys to use for the query |
||
228 | * @param ConnectionInterface $con an optional connection object |
||
229 | * |
||
230 | * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter |
||
231 | */ |
||
232 | public function findPks($keys, ConnectionInterface $con = null) |
||
245 | |||
246 | /** |
||
247 | * Filter the query by primary key |
||
248 | * |
||
249 | * @param mixed $key Primary key to use for the query |
||
250 | * |
||
251 | * @return $this|ChildPageLinkQuery The current query, for fluid interface |
||
252 | */ |
||
253 | public function filterByPrimaryKey($key) |
||
258 | |||
259 | /** |
||
260 | * Filter the query by a list of primary keys |
||
261 | * |
||
262 | * @param array $keys The list of primary key to use for the query |
||
263 | * |
||
264 | * @return $this|ChildPageLinkQuery The current query, for fluid interface |
||
265 | */ |
||
266 | public function filterByPrimaryKeys($keys) |
||
271 | |||
272 | /** |
||
273 | * Filter the query on the id column |
||
274 | * |
||
275 | * Example usage: |
||
276 | * <code> |
||
277 | * $query->filterById(1234); // WHERE id = 1234 |
||
278 | * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) |
||
279 | * $query->filterById(array('min' => 12)); // WHERE id > 12 |
||
280 | * </code> |
||
281 | * |
||
282 | * @param mixed $id The value to use as filter. |
||
283 | * Use scalar values for equality. |
||
284 | * Use array values for in_array() equivalent. |
||
285 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
286 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
287 | * |
||
288 | * @return $this|ChildPageLinkQuery The current query, for fluid interface |
||
289 | */ |
||
290 | public function filterById($id = null, $comparison = null) |
||
312 | |||
313 | /** |
||
314 | * Filter the query on the page_id column |
||
315 | * |
||
316 | * Example usage: |
||
317 | * <code> |
||
318 | * $query->filterByPageId(1234); // WHERE page_id = 1234 |
||
319 | * $query->filterByPageId(array(12, 34)); // WHERE page_id IN (12, 34) |
||
320 | * $query->filterByPageId(array('min' => 12)); // WHERE page_id > 12 |
||
321 | * </code> |
||
322 | * |
||
323 | * @param mixed $pageId The value to use as filter. |
||
324 | * Use scalar values for equality. |
||
325 | * Use array values for in_array() equivalent. |
||
326 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
327 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
328 | * |
||
329 | * @return $this|ChildPageLinkQuery The current query, for fluid interface |
||
330 | */ |
||
331 | public function filterByPageId($pageId = null, $comparison = null) |
||
353 | |||
354 | /** |
||
355 | * Filter the query on the active_from column |
||
356 | * |
||
357 | * Example usage: |
||
358 | * <code> |
||
359 | * $query->filterByActiveFrom(1234); // WHERE active_from = 1234 |
||
360 | * $query->filterByActiveFrom(array(12, 34)); // WHERE active_from IN (12, 34) |
||
361 | * $query->filterByActiveFrom(array('min' => 12)); // WHERE active_from > 12 |
||
362 | * </code> |
||
363 | * |
||
364 | * @param mixed $activeFrom The value to use as filter. |
||
365 | * Use scalar values for equality. |
||
366 | * Use array values for in_array() equivalent. |
||
367 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
368 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
369 | * |
||
370 | * @return $this|ChildPageLinkQuery The current query, for fluid interface |
||
371 | */ |
||
372 | public function filterByActiveFrom($activeFrom = null, $comparison = null) |
||
394 | |||
395 | /** |
||
396 | * Filter the query on the active_to column |
||
397 | * |
||
398 | * Example usage: |
||
399 | * <code> |
||
400 | * $query->filterByActiveTo(1234); // WHERE active_to = 1234 |
||
401 | * $query->filterByActiveTo(array(12, 34)); // WHERE active_to IN (12, 34) |
||
402 | * $query->filterByActiveTo(array('min' => 12)); // WHERE active_to > 12 |
||
403 | * </code> |
||
404 | * |
||
405 | * @param mixed $activeTo The value to use as filter. |
||
406 | * Use scalar values for equality. |
||
407 | * Use array values for in_array() equivalent. |
||
408 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
409 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
410 | * |
||
411 | * @return $this|ChildPageLinkQuery The current query, for fluid interface |
||
412 | */ |
||
413 | public function filterByActiveTo($activeTo = null, $comparison = null) |
||
435 | |||
436 | /** |
||
437 | * Filter the query on the show_on column |
||
438 | * |
||
439 | * Example usage: |
||
440 | * <code> |
||
441 | * $query->filterByShowOn(true); // WHERE show_on = true |
||
442 | * $query->filterByShowOn('yes'); // WHERE show_on = true |
||
443 | * </code> |
||
444 | * |
||
445 | * @param boolean|string $showOn The value to use as filter. |
||
446 | * Non-boolean arguments are converted using the following rules: |
||
447 | * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true |
||
448 | * * 0, '0', 'false', 'off', and 'no' are converted to boolean false |
||
449 | * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). |
||
450 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
451 | * |
||
452 | * @return $this|ChildPageLinkQuery The current query, for fluid interface |
||
453 | */ |
||
454 | View Code Duplication | public function filterByShowOn($showOn = null, $comparison = null) |
|
462 | |||
463 | /** |
||
464 | * Filter the query on the permanent column |
||
465 | * |
||
466 | * Example usage: |
||
467 | * <code> |
||
468 | * $query->filterByPermanent(true); // WHERE permanent = true |
||
469 | * $query->filterByPermanent('yes'); // WHERE permanent = true |
||
470 | * </code> |
||
471 | * |
||
472 | * @param boolean|string $permanent The value to use as filter. |
||
473 | * Non-boolean arguments are converted using the following rules: |
||
474 | * * 1, '1', 'true', 'on', and 'yes' are converted to boolean true |
||
475 | * * 0, '0', 'false', 'off', and 'no' are converted to boolean false |
||
476 | * Check on string values is case insensitive (so 'FaLsE' is seen as 'false'). |
||
477 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
478 | * |
||
479 | * @return $this|ChildPageLinkQuery The current query, for fluid interface |
||
480 | */ |
||
481 | View Code Duplication | public function filterByPermanent($permanent = null, $comparison = null) |
|
489 | |||
490 | /** |
||
491 | * Filter the query by a related \mod_link\models\PageLinkProduct object |
||
492 | * |
||
493 | * @param \mod_link\models\PageLinkProduct|ObjectCollection $pageLinkProduct the related object to use as filter |
||
494 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
495 | * |
||
496 | * @return ChildPageLinkQuery The current query, for fluid interface |
||
497 | */ |
||
498 | View Code Duplication | public function filterByPageLinkProduct($pageLinkProduct, $comparison = null) |
|
512 | |||
513 | /** |
||
514 | * Adds a JOIN clause to the query using the PageLinkProduct relation |
||
515 | * |
||
516 | * @param string $relationAlias optional alias for the relation |
||
517 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
518 | * |
||
519 | * @return $this|ChildPageLinkQuery The current query, for fluid interface |
||
520 | */ |
||
521 | public function joinPageLinkProduct($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
||
544 | |||
545 | /** |
||
546 | * Use the PageLinkProduct relation PageLinkProduct object |
||
547 | * |
||
548 | * @see useQuery() |
||
549 | * |
||
550 | * @param string $relationAlias optional alias for the relation, |
||
551 | * to be used as main alias in the secondary query |
||
552 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
553 | * |
||
554 | * @return \mod_link\models\PageLinkProductQuery A secondary query class using the current class as primary query |
||
555 | */ |
||
556 | public function usePageLinkProductQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
||
562 | |||
563 | /** |
||
564 | * Exclude object from result |
||
565 | * |
||
566 | * @param ChildPageLink $pageLink Object to remove from the list of results |
||
567 | * |
||
568 | * @return $this|ChildPageLinkQuery The current query, for fluid interface |
||
569 | */ |
||
570 | public function prune($pageLink = null) |
||
578 | |||
579 | /** |
||
580 | * Deletes all rows from the page_link table. |
||
581 | * |
||
582 | * @param ConnectionInterface $con the connection to use |
||
583 | * @return int The number of affected rows (if supported by underlying database driver). |
||
584 | */ |
||
585 | public function doDeleteAll(ConnectionInterface $con = null) |
||
605 | |||
606 | /** |
||
607 | * Performs a DELETE on the database based on the current ModelCriteria |
||
608 | * |
||
609 | * @param ConnectionInterface $con the connection to use |
||
610 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
611 | * if supported by native driver or if emulated using Propel. |
||
612 | * @throws PropelException Any exceptions caught during processing will be |
||
613 | * rethrown wrapped into a PropelException. |
||
614 | */ |
||
615 | public function delete(ConnectionInterface $con = null) |
||
639 | |||
640 | } // PageLinkQuery |
||
641 |