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 PageLinkProductsQuery 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 PageLinkProductsQuery, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
67 | View Code Duplication | abstract class PageLinkProductsQuery extends ModelCriteria |
|
68 | { |
||
69 | protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException'; |
||
70 | |||
71 | /** |
||
72 | * Initializes internal state of \mod_link\models\Base\PageLinkProductsQuery object. |
||
73 | * |
||
74 | * @param string $dbName The database name |
||
75 | * @param string $modelName The phpName of a model, e.g. 'Book' |
||
76 | * @param string $modelAlias The alias for the model in this query, e.g. 'b' |
||
77 | */ |
||
78 | public function __construct($dbName = 'Shop', $modelName = '\\mod_link\\models\\PageLinkProducts', $modelAlias = null) |
||
82 | |||
83 | /** |
||
84 | * Returns a new ChildPageLinkProductsQuery object. |
||
85 | * |
||
86 | * @param string $modelAlias The alias of a model in the query |
||
87 | * @param Criteria $criteria Optional Criteria to build the query from |
||
88 | * |
||
89 | * @return ChildPageLinkProductsQuery |
||
90 | */ |
||
91 | public static function create($modelAlias = null, Criteria $criteria = null) |
||
106 | |||
107 | /** |
||
108 | * Find object by primary key. |
||
109 | * Propel uses the instance pool to skip the database if the object exists. |
||
110 | * Go fast if the query is untouched. |
||
111 | * |
||
112 | * <code> |
||
113 | * $obj = $c->findPk(array(12, 34), $con); |
||
114 | * </code> |
||
115 | * |
||
116 | * @param array[$link_id, $product_id] $key Primary key to use for the query |
||
117 | * @param ConnectionInterface $con an optional connection object |
||
118 | * |
||
119 | * @return ChildPageLinkProducts|array|mixed the result, formatted by the current formatter |
||
120 | */ |
||
121 | public function findPk($key, ConnectionInterface $con = null) |
||
142 | |||
143 | /** |
||
144 | * Find object by primary key using raw SQL to go fast. |
||
145 | * Bypass doSelect() and the object formatter by using generated code. |
||
146 | * |
||
147 | * @param mixed $key Primary key to use for the query |
||
148 | * @param ConnectionInterface $con A connection object |
||
149 | * |
||
150 | * @throws \Propel\Runtime\Exception\PropelException |
||
151 | * |
||
152 | * @return ChildPageLinkProducts A model object, or null if the key is not found |
||
153 | */ |
||
154 | protected function findPkSimple($key, ConnectionInterface $con) |
||
177 | |||
178 | /** |
||
179 | * Find object by primary key. |
||
180 | * |
||
181 | * @param mixed $key Primary key to use for the query |
||
182 | * @param ConnectionInterface $con A connection object |
||
183 | * |
||
184 | * @return ChildPageLinkProducts|array|mixed the result, formatted by the current formatter |
||
185 | */ |
||
186 | protected function findPkComplex($key, ConnectionInterface $con) |
||
196 | |||
197 | /** |
||
198 | * Find objects by primary key |
||
199 | * <code> |
||
200 | * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con); |
||
201 | * </code> |
||
202 | * @param array $keys Primary keys to use for the query |
||
203 | * @param ConnectionInterface $con an optional connection object |
||
204 | * |
||
205 | * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter |
||
206 | */ |
||
207 | public function findPks($keys, ConnectionInterface $con = null) |
||
220 | |||
221 | /** |
||
222 | * Filter the query by primary key |
||
223 | * |
||
224 | * @param mixed $key Primary key to use for the query |
||
225 | * |
||
226 | * @return $this|ChildPageLinkProductsQuery The current query, for fluid interface |
||
227 | */ |
||
228 | public function filterByPrimaryKey($key) |
||
235 | |||
236 | /** |
||
237 | * Filter the query by a list of primary keys |
||
238 | * |
||
239 | * @param array $keys The list of primary key to use for the query |
||
240 | * |
||
241 | * @return $this|ChildPageLinkProductsQuery The current query, for fluid interface |
||
242 | */ |
||
243 | public function filterByPrimaryKeys($keys) |
||
257 | |||
258 | /** |
||
259 | * Filter the query on the link_id column |
||
260 | * |
||
261 | * Example usage: |
||
262 | * <code> |
||
263 | * $query->filterByLinkId(1234); // WHERE link_id = 1234 |
||
264 | * $query->filterByLinkId(array(12, 34)); // WHERE link_id IN (12, 34) |
||
265 | * $query->filterByLinkId(array('min' => 12)); // WHERE link_id > 12 |
||
266 | * </code> |
||
267 | * |
||
268 | * @see filterByPageLink() |
||
269 | * |
||
270 | * @param mixed $linkId The value to use as filter. |
||
271 | * Use scalar values for equality. |
||
272 | * Use array values for in_array() equivalent. |
||
273 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
274 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
275 | * |
||
276 | * @return $this|ChildPageLinkProductsQuery The current query, for fluid interface |
||
277 | */ |
||
278 | public function filterByLinkId($linkId = null, $comparison = null) |
||
300 | |||
301 | /** |
||
302 | * Filter the query on the product_id column |
||
303 | * |
||
304 | * Example usage: |
||
305 | * <code> |
||
306 | * $query->filterByProductId(1234); // WHERE product_id = 1234 |
||
307 | * $query->filterByProductId(array(12, 34)); // WHERE product_id IN (12, 34) |
||
308 | * $query->filterByProductId(array('min' => 12)); // WHERE product_id > 12 |
||
309 | * </code> |
||
310 | * |
||
311 | * @param mixed $productId The value to use as filter. |
||
312 | * Use scalar values for equality. |
||
313 | * Use array values for in_array() equivalent. |
||
314 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
315 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
316 | * |
||
317 | * @return $this|ChildPageLinkProductsQuery The current query, for fluid interface |
||
318 | */ |
||
319 | public function filterByProductId($productId = null, $comparison = null) |
||
341 | |||
342 | /** |
||
343 | * Filter the query by a related \mod_link\models\PageLink object |
||
344 | * |
||
345 | * @param \mod_link\models\PageLink|ObjectCollection $pageLink The related object(s) to use as filter |
||
346 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
347 | * |
||
348 | * @throws \Propel\Runtime\Exception\PropelException |
||
349 | * |
||
350 | * @return ChildPageLinkProductsQuery The current query, for fluid interface |
||
351 | */ |
||
352 | public function filterByPageLink($pageLink, $comparison = null) |
||
368 | |||
369 | /** |
||
370 | * Adds a JOIN clause to the query using the PageLink relation |
||
371 | * |
||
372 | * @param string $relationAlias optional alias for the relation |
||
373 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
374 | * |
||
375 | * @return $this|ChildPageLinkProductsQuery The current query, for fluid interface |
||
376 | */ |
||
377 | public function joinPageLink($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
||
400 | |||
401 | /** |
||
402 | * Use the PageLink relation PageLink object |
||
403 | * |
||
404 | * @see useQuery() |
||
405 | * |
||
406 | * @param string $relationAlias optional alias for the relation, |
||
407 | * to be used as main alias in the secondary query |
||
408 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
409 | * |
||
410 | * @return \mod_link\models\PageLinkQuery A secondary query class using the current class as primary query |
||
411 | */ |
||
412 | public function usePageLinkQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
||
418 | |||
419 | /** |
||
420 | * Exclude object from result |
||
421 | * |
||
422 | * @param ChildPageLinkProducts $pageLinkProducts Object to remove from the list of results |
||
423 | * |
||
424 | * @return $this|ChildPageLinkProductsQuery The current query, for fluid interface |
||
425 | */ |
||
426 | public function prune($pageLinkProducts = null) |
||
436 | |||
437 | /** |
||
438 | * Deletes all rows from the page_link_products table. |
||
439 | * |
||
440 | * @param ConnectionInterface $con the connection to use |
||
441 | * @return int The number of affected rows (if supported by underlying database driver). |
||
442 | */ |
||
443 | public function doDeleteAll(ConnectionInterface $con = null) |
||
463 | |||
464 | /** |
||
465 | * Performs a DELETE on the database based on the current ModelCriteria |
||
466 | * |
||
467 | * @param ConnectionInterface $con the connection to use |
||
468 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
469 | * if supported by native driver or if emulated using Propel. |
||
470 | * @throws PropelException Any exceptions caught during processing will be |
||
471 | * rethrown wrapped into a PropelException. |
||
472 | */ |
||
473 | public function delete(ConnectionInterface $con = null) |
||
497 | |||
498 | } // PageLinkProductsQuery |
||
499 |