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 RouteQuery 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 RouteQuery, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
96 | abstract class RouteQuery extends ModelCriteria |
||
97 | { |
||
98 | protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException'; |
||
99 | |||
100 | /** |
||
101 | * Initializes internal state of \core\models\Base\RouteQuery object. |
||
102 | * |
||
103 | * @param string $dbName The database name |
||
104 | * @param string $modelName The phpName of a model, e.g. 'Book' |
||
105 | * @param string $modelAlias The alias for the model in this query, e.g. 'b' |
||
106 | */ |
||
107 | public function __construct($dbName = 'Shop', $modelName = '\\core\\models\\Route', $modelAlias = null) |
||
111 | |||
112 | /** |
||
113 | * Returns a new ChildRouteQuery object. |
||
114 | * |
||
115 | * @param string $modelAlias The alias of a model in the query |
||
116 | * @param Criteria $criteria Optional Criteria to build the query from |
||
117 | * |
||
118 | * @return ChildRouteQuery |
||
119 | */ |
||
120 | public static function create($modelAlias = null, Criteria $criteria = null) |
||
135 | |||
136 | /** |
||
137 | * Find object by primary key. |
||
138 | * Propel uses the instance pool to skip the database if the object exists. |
||
139 | * Go fast if the query is untouched. |
||
140 | * |
||
141 | * <code> |
||
142 | * $obj = $c->findPk(12, $con); |
||
143 | * </code> |
||
144 | * |
||
145 | * @param mixed $key Primary key to use for the query |
||
146 | * @param ConnectionInterface $con an optional connection object |
||
147 | * |
||
148 | * @return ChildRoute|array|mixed the result, formatted by the current formatter |
||
149 | */ |
||
150 | View Code Duplication | public function findPk($key, ConnectionInterface $con = null) |
|
177 | |||
178 | /** |
||
179 | * Find object by primary key using raw SQL to go fast. |
||
180 | * Bypass doSelect() and the object formatter by using generated code. |
||
181 | * |
||
182 | * @param mixed $key Primary key to use for the query |
||
183 | * @param ConnectionInterface $con A connection object |
||
184 | * |
||
185 | * @throws \Propel\Runtime\Exception\PropelException |
||
186 | * |
||
187 | * @return ChildRoute A model object, or null if the key is not found |
||
188 | */ |
||
189 | protected function findPkSimple($key, ConnectionInterface $con) |
||
211 | |||
212 | /** |
||
213 | * Find object by primary key. |
||
214 | * |
||
215 | * @param mixed $key Primary key to use for the query |
||
216 | * @param ConnectionInterface $con A connection object |
||
217 | * |
||
218 | * @return ChildRoute|array|mixed the result, formatted by the current formatter |
||
219 | */ |
||
220 | View Code Duplication | protected function findPkComplex($key, ConnectionInterface $con) |
|
230 | |||
231 | /** |
||
232 | * Find objects by primary key |
||
233 | * <code> |
||
234 | * $objs = $c->findPks(array(12, 56, 832), $con); |
||
235 | * </code> |
||
236 | * @param array $keys Primary keys to use for the query |
||
237 | * @param ConnectionInterface $con an optional connection object |
||
238 | * |
||
239 | * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter |
||
240 | */ |
||
241 | View Code Duplication | public function findPks($keys, ConnectionInterface $con = null) |
|
254 | |||
255 | /** |
||
256 | * Filter the query by primary key |
||
257 | * |
||
258 | * @param mixed $key Primary key to use for the query |
||
259 | * |
||
260 | * @return $this|ChildRouteQuery The current query, for fluid interface |
||
261 | */ |
||
262 | public function filterByPrimaryKey($key) |
||
267 | |||
268 | /** |
||
269 | * Filter the query by a list of primary keys |
||
270 | * |
||
271 | * @param array $keys The list of primary key to use for the query |
||
272 | * |
||
273 | * @return $this|ChildRouteQuery The current query, for fluid interface |
||
274 | */ |
||
275 | public function filterByPrimaryKeys($keys) |
||
280 | |||
281 | /** |
||
282 | * Filter the query on the id column |
||
283 | * |
||
284 | * Example usage: |
||
285 | * <code> |
||
286 | * $query->filterById(1234); // WHERE id = 1234 |
||
287 | * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) |
||
288 | * $query->filterById(array('min' => 12)); // WHERE id > 12 |
||
289 | * </code> |
||
290 | * |
||
291 | * @param mixed $id The value to use as filter. |
||
292 | * Use scalar values for equality. |
||
293 | * Use array values for in_array() equivalent. |
||
294 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
295 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
296 | * |
||
297 | * @return $this|ChildRouteQuery The current query, for fluid interface |
||
298 | */ |
||
299 | public function filterById($id = null, $comparison = null) |
||
321 | |||
322 | /** |
||
323 | * Filter the query on the entity_id column |
||
324 | * |
||
325 | * Example usage: |
||
326 | * <code> |
||
327 | * $query->filterByEntityId(1234); // WHERE entity_id = 1234 |
||
328 | * $query->filterByEntityId(array(12, 34)); // WHERE entity_id IN (12, 34) |
||
329 | * $query->filterByEntityId(array('min' => 12)); // WHERE entity_id > 12 |
||
330 | * </code> |
||
331 | * |
||
332 | * @param mixed $entityId The value to use as filter. |
||
333 | * Use scalar values for equality. |
||
334 | * Use array values for in_array() equivalent. |
||
335 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
336 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
337 | * |
||
338 | * @return $this|ChildRouteQuery The current query, for fluid interface |
||
339 | */ |
||
340 | public function filterByEntityId($entityId = null, $comparison = null) |
||
362 | |||
363 | /** |
||
364 | * Filter the query on the type column |
||
365 | * |
||
366 | * Example usage: |
||
367 | * <code> |
||
368 | * $query->filterByType('fooValue'); // WHERE type = 'fooValue' |
||
369 | * $query->filterByType('%fooValue%', Criteria::LIKE); // WHERE type LIKE '%fooValue%' |
||
370 | * </code> |
||
371 | * |
||
372 | * @param string $type The value to use as filter. |
||
373 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
374 | * |
||
375 | * @return $this|ChildRouteQuery The current query, for fluid interface |
||
376 | */ |
||
377 | View Code Duplication | public function filterByType($type = null, $comparison = null) |
|
387 | |||
388 | /** |
||
389 | * Filter the query on the parent_url column |
||
390 | * |
||
391 | * Example usage: |
||
392 | * <code> |
||
393 | * $query->filterByParentUrl('fooValue'); // WHERE parent_url = 'fooValue' |
||
394 | * $query->filterByParentUrl('%fooValue%', Criteria::LIKE); // WHERE parent_url LIKE '%fooValue%' |
||
395 | * </code> |
||
396 | * |
||
397 | * @param string $parentUrl The value to use as filter. |
||
398 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
399 | * |
||
400 | * @return $this|ChildRouteQuery The current query, for fluid interface |
||
401 | */ |
||
402 | View Code Duplication | public function filterByParentUrl($parentUrl = null, $comparison = null) |
|
412 | |||
413 | /** |
||
414 | * Filter the query on the url column |
||
415 | * |
||
416 | * Example usage: |
||
417 | * <code> |
||
418 | * $query->filterByUrl('fooValue'); // WHERE url = 'fooValue' |
||
419 | * $query->filterByUrl('%fooValue%', Criteria::LIKE); // WHERE url LIKE '%fooValue%' |
||
420 | * </code> |
||
421 | * |
||
422 | * @param string $url The value to use as filter. |
||
423 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
424 | * |
||
425 | * @return $this|ChildRouteQuery The current query, for fluid interface |
||
426 | */ |
||
427 | View Code Duplication | public function filterByUrl($url = null, $comparison = null) |
|
437 | |||
438 | /** |
||
439 | * Filter the query by a related \SCategory object |
||
440 | * |
||
441 | * @param \SCategory|ObjectCollection $sCategory the related object to use as filter |
||
442 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
443 | * |
||
444 | * @return ChildRouteQuery The current query, for fluid interface |
||
445 | */ |
||
446 | View Code Duplication | public function filterBySCategory($sCategory, $comparison = null) |
|
460 | |||
461 | /** |
||
462 | * Adds a JOIN clause to the query using the SCategory relation |
||
463 | * |
||
464 | * @param string $relationAlias optional alias for the relation |
||
465 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
466 | * |
||
467 | * @return $this|ChildRouteQuery The current query, for fluid interface |
||
468 | */ |
||
469 | View Code Duplication | public function joinSCategory($relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
|
492 | |||
493 | /** |
||
494 | * Use the SCategory relation SCategory object |
||
495 | * |
||
496 | * @see useQuery() |
||
497 | * |
||
498 | * @param string $relationAlias optional alias for the relation, |
||
499 | * to be used as main alias in the secondary query |
||
500 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
501 | * |
||
502 | * @return \SCategoryQuery A secondary query class using the current class as primary query |
||
503 | */ |
||
504 | public function useSCategoryQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
||
510 | |||
511 | /** |
||
512 | * Filter the query by a related \SProducts object |
||
513 | * |
||
514 | * @param \SProducts|ObjectCollection $sProducts the related object to use as filter |
||
515 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
516 | * |
||
517 | * @return ChildRouteQuery The current query, for fluid interface |
||
518 | */ |
||
519 | View Code Duplication | public function filterBySProducts($sProducts, $comparison = null) |
|
533 | |||
534 | /** |
||
535 | * Adds a JOIN clause to the query using the SProducts relation |
||
536 | * |
||
537 | * @param string $relationAlias optional alias for the relation |
||
538 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
539 | * |
||
540 | * @return $this|ChildRouteQuery The current query, for fluid interface |
||
541 | */ |
||
542 | View Code Duplication | public function joinSProducts($relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
|
565 | |||
566 | /** |
||
567 | * Use the SProducts relation SProducts object |
||
568 | * |
||
569 | * @see useQuery() |
||
570 | * |
||
571 | * @param string $relationAlias optional alias for the relation, |
||
572 | * to be used as main alias in the secondary query |
||
573 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
574 | * |
||
575 | * @return \SProductsQuery A secondary query class using the current class as primary query |
||
576 | */ |
||
577 | public function useSProductsQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
||
583 | |||
584 | /** |
||
585 | * Exclude object from result |
||
586 | * |
||
587 | * @param ChildRoute $route Object to remove from the list of results |
||
588 | * |
||
589 | * @return $this|ChildRouteQuery The current query, for fluid interface |
||
590 | */ |
||
591 | public function prune($route = null) |
||
599 | |||
600 | /** |
||
601 | * Deletes all rows from the route table. |
||
602 | * |
||
603 | * @param ConnectionInterface $con the connection to use |
||
604 | * @return int The number of affected rows (if supported by underlying database driver). |
||
605 | */ |
||
606 | View Code Duplication | public function doDeleteAll(ConnectionInterface $con = null) |
|
627 | |||
628 | /** |
||
629 | * Performs a DELETE on the database based on the current ModelCriteria |
||
630 | * |
||
631 | * @param ConnectionInterface $con the connection to use |
||
632 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
633 | * if supported by native driver or if emulated using Propel. |
||
634 | * @throws PropelException Any exceptions caught during processing will be |
||
635 | * rethrown wrapped into a PropelException. |
||
636 | */ |
||
637 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
665 | |||
666 | /** |
||
667 | * This is a method for emulating ON DELETE CASCADE for DBs that don't support this |
||
668 | * feature (like MySQL or SQLite). |
||
669 | * |
||
670 | * This method is not very speedy because it must perform a query first to get |
||
671 | * the implicated records and then perform the deletes by calling those Query classes. |
||
672 | * |
||
673 | * This method should be used within a transaction if possible. |
||
674 | * |
||
675 | * @param ConnectionInterface $con |
||
676 | * @return int The number of affected rows (if supported by underlying database driver). |
||
677 | */ |
||
678 | protected function doOnDeleteCascade(ConnectionInterface $con) |
||
703 | |||
704 | } // RouteQuery |
||
705 |