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 PageLinkProductQuery 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 PageLinkProductQuery, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 67 | View Code Duplication | abstract class PageLinkProductQuery extends ModelCriteria |
|
| 68 | { |
||
| 69 | protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException'; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Initializes internal state of \mod_link\models\Base\PageLinkProductQuery 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\\PageLinkProduct', $modelAlias = null) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Returns a new ChildPageLinkProductQuery 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 ChildPageLinkProductQuery |
||
| 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 ChildPageLinkProduct|array|mixed the result, formatted by the current formatter |
||
| 120 | */ |
||
| 121 | public function findPk($key, ConnectionInterface $con = null) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Find object by primary key using raw SQL to go fast. |
||
| 151 | * Bypass doSelect() and the object formatter by using generated code. |
||
| 152 | * |
||
| 153 | * @param mixed $key Primary key to use for the query |
||
| 154 | * @param ConnectionInterface $con A connection object |
||
| 155 | * |
||
| 156 | * @throws \Propel\Runtime\Exception\PropelException |
||
| 157 | * |
||
| 158 | * @return ChildPageLinkProduct A model object, or null if the key is not found |
||
| 159 | */ |
||
| 160 | protected function findPkSimple($key, ConnectionInterface $con) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Find object by primary key. |
||
| 186 | * |
||
| 187 | * @param mixed $key Primary key to use for the query |
||
| 188 | * @param ConnectionInterface $con A connection object |
||
| 189 | * |
||
| 190 | * @return ChildPageLinkProduct|array|mixed the result, formatted by the current formatter |
||
| 191 | */ |
||
| 192 | protected function findPkComplex($key, ConnectionInterface $con) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Find objects by primary key |
||
| 205 | * <code> |
||
| 206 | * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con); |
||
| 207 | * </code> |
||
| 208 | * @param array $keys Primary keys to use for the query |
||
| 209 | * @param ConnectionInterface $con an optional connection object |
||
| 210 | * |
||
| 211 | * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter |
||
| 212 | */ |
||
| 213 | public function findPks($keys, ConnectionInterface $con = null) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Filter the query by primary key |
||
| 229 | * |
||
| 230 | * @param mixed $key Primary key to use for the query |
||
| 231 | * |
||
| 232 | * @return $this|ChildPageLinkProductQuery The current query, for fluid interface |
||
| 233 | */ |
||
| 234 | public function filterByPrimaryKey($key) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Filter the query by a list of primary keys |
||
| 244 | * |
||
| 245 | * @param array $keys The list of primary key to use for the query |
||
| 246 | * |
||
| 247 | * @return $this|ChildPageLinkProductQuery The current query, for fluid interface |
||
| 248 | */ |
||
| 249 | public function filterByPrimaryKeys($keys) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Filter the query on the link_id column |
||
| 266 | * |
||
| 267 | * Example usage: |
||
| 268 | * <code> |
||
| 269 | * $query->filterByLinkId(1234); // WHERE link_id = 1234 |
||
| 270 | * $query->filterByLinkId(array(12, 34)); // WHERE link_id IN (12, 34) |
||
| 271 | * $query->filterByLinkId(array('min' => 12)); // WHERE link_id > 12 |
||
| 272 | * </code> |
||
| 273 | * |
||
| 274 | * @see filterByPageLink() |
||
| 275 | * |
||
| 276 | * @param mixed $linkId The value to use as filter. |
||
| 277 | * Use scalar values for equality. |
||
| 278 | * Use array values for in_array() equivalent. |
||
| 279 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
| 280 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 281 | * |
||
| 282 | * @return $this|ChildPageLinkProductQuery The current query, for fluid interface |
||
| 283 | */ |
||
| 284 | public function filterByLinkId($linkId = null, $comparison = null) |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Filter the query on the product_id column |
||
| 309 | * |
||
| 310 | * Example usage: |
||
| 311 | * <code> |
||
| 312 | * $query->filterByProductId(1234); // WHERE product_id = 1234 |
||
| 313 | * $query->filterByProductId(array(12, 34)); // WHERE product_id IN (12, 34) |
||
| 314 | * $query->filterByProductId(array('min' => 12)); // WHERE product_id > 12 |
||
| 315 | * </code> |
||
| 316 | * |
||
| 317 | * @param mixed $productId The value to use as filter. |
||
| 318 | * Use scalar values for equality. |
||
| 319 | * Use array values for in_array() equivalent. |
||
| 320 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
| 321 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 322 | * |
||
| 323 | * @return $this|ChildPageLinkProductQuery The current query, for fluid interface |
||
| 324 | */ |
||
| 325 | public function filterByProductId($productId = null, $comparison = null) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Filter the query by a related \mod_link\models\PageLink object |
||
| 350 | * |
||
| 351 | * @param \mod_link\models\PageLink|ObjectCollection $pageLink The related object(s) to use as filter |
||
| 352 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
| 353 | * |
||
| 354 | * @throws \Propel\Runtime\Exception\PropelException |
||
| 355 | * |
||
| 356 | * @return ChildPageLinkProductQuery The current query, for fluid interface |
||
| 357 | */ |
||
| 358 | public function filterByPageLink($pageLink, $comparison = null) |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Adds a JOIN clause to the query using the PageLink relation |
||
| 377 | * |
||
| 378 | * @param string $relationAlias optional alias for the relation |
||
| 379 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
| 380 | * |
||
| 381 | * @return $this|ChildPageLinkProductQuery The current query, for fluid interface |
||
| 382 | */ |
||
| 383 | public function joinPageLink($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Use the PageLink relation PageLink object |
||
| 409 | * |
||
| 410 | * @see useQuery() |
||
| 411 | * |
||
| 412 | * @param string $relationAlias optional alias for the relation, |
||
| 413 | * to be used as main alias in the secondary query |
||
| 414 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
| 415 | * |
||
| 416 | * @return \mod_link\models\PageLinkQuery A secondary query class using the current class as primary query |
||
| 417 | */ |
||
| 418 | public function usePageLinkQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Exclude object from result |
||
| 427 | * |
||
| 428 | * @param ChildPageLinkProduct $pageLinkProduct Object to remove from the list of results |
||
| 429 | * |
||
| 430 | * @return $this|ChildPageLinkProductQuery The current query, for fluid interface |
||
| 431 | */ |
||
| 432 | public function prune($pageLinkProduct = null) |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Deletes all rows from the page_link_product table. |
||
| 445 | * |
||
| 446 | * @param ConnectionInterface $con the connection to use |
||
| 447 | * @return int The number of affected rows (if supported by underlying database driver). |
||
| 448 | */ |
||
| 449 | public function doDeleteAll(ConnectionInterface $con = null) |
||
| 469 | |||
| 470 | /** |
||
| 471 | * Performs a DELETE on the database based on the current ModelCriteria |
||
| 472 | * |
||
| 473 | * @param ConnectionInterface $con the connection to use |
||
| 474 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
| 475 | * if supported by native driver or if emulated using Propel. |
||
| 476 | * @throws PropelException Any exceptions caught during processing will be |
||
| 477 | * rethrown wrapped into a PropelException. |
||
| 478 | */ |
||
| 479 | public function delete(ConnectionInterface $con = null) |
||
| 503 | |||
| 504 | } // PageLinkProductQuery |
||
| 505 |