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 InputQuery 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 InputQuery, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
102 | abstract class InputQuery extends ModelCriteria |
||
103 | { |
||
104 | protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException'; |
||
105 | |||
106 | /** |
||
107 | * Initializes internal state of \Jalle19\StatusManager\Database\Base\InputQuery object. |
||
108 | * |
||
109 | * @param string $dbName The database name |
||
110 | * @param string $modelName The phpName of a model, e.g. 'Book' |
||
111 | * @param string $modelAlias The alias for the model in this query, e.g. 'b' |
||
112 | */ |
||
113 | public function __construct($dbName = 'tvheadend_status_manager', $modelName = '\\Jalle19\\StatusManager\\Database\\Input', $modelAlias = null) |
||
117 | |||
118 | /** |
||
119 | * Returns a new ChildInputQuery object. |
||
120 | * |
||
121 | * @param string $modelAlias The alias of a model in the query |
||
122 | * @param Criteria $criteria Optional Criteria to build the query from |
||
123 | * |
||
124 | * @return ChildInputQuery |
||
125 | */ |
||
126 | public static function create($modelAlias = null, Criteria $criteria = null) |
||
141 | |||
142 | /** |
||
143 | * Find object by primary key. |
||
144 | * Propel uses the instance pool to skip the database if the object exists. |
||
145 | * Go fast if the query is untouched. |
||
146 | * |
||
147 | * <code> |
||
148 | * $obj = $c->findPk(12, $con); |
||
149 | * </code> |
||
150 | * |
||
151 | * @param mixed $key Primary key to use for the query |
||
152 | * @param ConnectionInterface $con an optional connection object |
||
153 | * |
||
154 | * @return ChildInput|array|mixed the result, formatted by the current formatter |
||
155 | */ |
||
156 | 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 ChildInput 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 ChildInput|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|ChildInputQuery 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|ChildInputQuery The current query, for fluid interface |
||
274 | */ |
||
275 | public function filterByPrimaryKeys($keys) |
||
280 | |||
281 | /** |
||
282 | * Filter the query on the uuid column |
||
283 | * |
||
284 | * Example usage: |
||
285 | * <code> |
||
286 | * $query->filterByUuid('fooValue'); // WHERE uuid = 'fooValue' |
||
287 | * $query->filterByUuid('%fooValue%'); // WHERE uuid LIKE '%fooValue%' |
||
288 | * </code> |
||
289 | * |
||
290 | * @param string $uuid The value to use as filter. |
||
291 | * Accepts wildcards (* and % trigger a LIKE) |
||
292 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
293 | * |
||
294 | * @return $this|ChildInputQuery The current query, for fluid interface |
||
295 | */ |
||
296 | View Code Duplication | public function filterByUuid($uuid = null, $comparison = null) |
|
309 | |||
310 | /** |
||
311 | * Filter the query on the instance_name column |
||
312 | * |
||
313 | * Example usage: |
||
314 | * <code> |
||
315 | * $query->filterByInstanceName('fooValue'); // WHERE instance_name = 'fooValue' |
||
316 | * $query->filterByInstanceName('%fooValue%'); // WHERE instance_name LIKE '%fooValue%' |
||
317 | * </code> |
||
318 | * |
||
319 | * @param string $instanceName The value to use as filter. |
||
320 | * Accepts wildcards (* and % trigger a LIKE) |
||
321 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
322 | * |
||
323 | * @return $this|ChildInputQuery The current query, for fluid interface |
||
324 | */ |
||
325 | View Code Duplication | public function filterByInstanceName($instanceName = null, $comparison = null) |
|
338 | |||
339 | /** |
||
340 | * Filter the query on the started column |
||
341 | * |
||
342 | * Example usage: |
||
343 | * <code> |
||
344 | * $query->filterByStarted('2011-03-14'); // WHERE started = '2011-03-14' |
||
345 | * $query->filterByStarted('now'); // WHERE started = '2011-03-14' |
||
346 | * $query->filterByStarted(array('max' => 'yesterday')); // WHERE started > '2011-03-13' |
||
347 | * </code> |
||
348 | * |
||
349 | * @param mixed $started The value to use as filter. |
||
350 | * Values can be integers (unix timestamps), DateTime objects, or strings. |
||
351 | * Empty strings are treated as NULL. |
||
352 | * Use scalar values for equality. |
||
353 | * Use array values for in_array() equivalent. |
||
354 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
355 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
356 | * |
||
357 | * @return $this|ChildInputQuery The current query, for fluid interface |
||
358 | */ |
||
359 | public function filterByStarted($started = null, $comparison = null) |
||
381 | |||
382 | /** |
||
383 | * Filter the query on the input column |
||
384 | * |
||
385 | * Example usage: |
||
386 | * <code> |
||
387 | * $query->filterByInput('fooValue'); // WHERE input = 'fooValue' |
||
388 | * $query->filterByInput('%fooValue%'); // WHERE input LIKE '%fooValue%' |
||
389 | * </code> |
||
390 | * |
||
391 | * @param string $input The value to use as filter. |
||
392 | * Accepts wildcards (* and % trigger a LIKE) |
||
393 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
394 | * |
||
395 | * @return $this|ChildInputQuery The current query, for fluid interface |
||
396 | */ |
||
397 | View Code Duplication | public function filterByInput($input = null, $comparison = null) |
|
410 | |||
411 | /** |
||
412 | * Filter the query on the network column |
||
413 | * |
||
414 | * Example usage: |
||
415 | * <code> |
||
416 | * $query->filterByNetwork('fooValue'); // WHERE network = 'fooValue' |
||
417 | * $query->filterByNetwork('%fooValue%'); // WHERE network LIKE '%fooValue%' |
||
418 | * </code> |
||
419 | * |
||
420 | * @param string $network The value to use as filter. |
||
421 | * Accepts wildcards (* and % trigger a LIKE) |
||
422 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
423 | * |
||
424 | * @return $this|ChildInputQuery The current query, for fluid interface |
||
425 | */ |
||
426 | View Code Duplication | public function filterByNetwork($network = null, $comparison = null) |
|
439 | |||
440 | /** |
||
441 | * Filter the query on the mux column |
||
442 | * |
||
443 | * Example usage: |
||
444 | * <code> |
||
445 | * $query->filterByMux('fooValue'); // WHERE mux = 'fooValue' |
||
446 | * $query->filterByMux('%fooValue%'); // WHERE mux LIKE '%fooValue%' |
||
447 | * </code> |
||
448 | * |
||
449 | * @param string $mux The value to use as filter. |
||
450 | * Accepts wildcards (* and % trigger a LIKE) |
||
451 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
452 | * |
||
453 | * @return $this|ChildInputQuery The current query, for fluid interface |
||
454 | */ |
||
455 | View Code Duplication | public function filterByMux($mux = null, $comparison = null) |
|
468 | |||
469 | /** |
||
470 | * Filter the query on the weight column |
||
471 | * |
||
472 | * Example usage: |
||
473 | * <code> |
||
474 | * $query->filterByWeight(1234); // WHERE weight = 1234 |
||
475 | * $query->filterByWeight(array(12, 34)); // WHERE weight IN (12, 34) |
||
476 | * $query->filterByWeight(array('min' => 12)); // WHERE weight > 12 |
||
477 | * </code> |
||
478 | * |
||
479 | * @param mixed $weight The value to use as filter. |
||
480 | * Use scalar values for equality. |
||
481 | * Use array values for in_array() equivalent. |
||
482 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
483 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
484 | * |
||
485 | * @return $this|ChildInputQuery The current query, for fluid interface |
||
486 | */ |
||
487 | public function filterByWeight($weight = null, $comparison = null) |
||
509 | |||
510 | /** |
||
511 | * Filter the query by a related \Jalle19\StatusManager\Database\Instance object |
||
512 | * |
||
513 | * @param \Jalle19\StatusManager\Database\Instance|ObjectCollection $instance The related object(s) to use as filter |
||
514 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
515 | * |
||
516 | * @throws \Propel\Runtime\Exception\PropelException |
||
517 | * |
||
518 | * @return ChildInputQuery The current query, for fluid interface |
||
519 | */ |
||
520 | View Code Duplication | public function filterByInstance($instance, $comparison = null) |
|
536 | |||
537 | /** |
||
538 | * Adds a JOIN clause to the query using the Instance relation |
||
539 | * |
||
540 | * @param string $relationAlias optional alias for the relation |
||
541 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
542 | * |
||
543 | * @return $this|ChildInputQuery The current query, for fluid interface |
||
544 | */ |
||
545 | View Code Duplication | public function joinInstance($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
|
568 | |||
569 | /** |
||
570 | * Use the Instance relation Instance object |
||
571 | * |
||
572 | * @see useQuery() |
||
573 | * |
||
574 | * @param string $relationAlias optional alias for the relation, |
||
575 | * to be used as main alias in the secondary query |
||
576 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
577 | * |
||
578 | * @return \Jalle19\StatusManager\Database\InstanceQuery A secondary query class using the current class as primary query |
||
579 | */ |
||
580 | public function useInstanceQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
||
586 | |||
587 | /** |
||
588 | * Filter the query by a related \Jalle19\StatusManager\Database\Subscription object |
||
589 | * |
||
590 | * @param \Jalle19\StatusManager\Database\Subscription|ObjectCollection $subscription the related object to use as filter |
||
591 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
592 | * |
||
593 | * @return ChildInputQuery The current query, for fluid interface |
||
594 | */ |
||
595 | View Code Duplication | public function filterBySubscription($subscription, $comparison = null) |
|
609 | |||
610 | /** |
||
611 | * Adds a JOIN clause to the query using the Subscription relation |
||
612 | * |
||
613 | * @param string $relationAlias optional alias for the relation |
||
614 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
615 | * |
||
616 | * @return $this|ChildInputQuery The current query, for fluid interface |
||
617 | */ |
||
618 | View Code Duplication | public function joinSubscription($relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
|
641 | |||
642 | /** |
||
643 | * Use the Subscription relation Subscription object |
||
644 | * |
||
645 | * @see useQuery() |
||
646 | * |
||
647 | * @param string $relationAlias optional alias for the relation, |
||
648 | * to be used as main alias in the secondary query |
||
649 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
650 | * |
||
651 | * @return \Jalle19\StatusManager\Database\SubscriptionQuery A secondary query class using the current class as primary query |
||
652 | */ |
||
653 | public function useSubscriptionQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
||
659 | |||
660 | /** |
||
661 | * Exclude object from result |
||
662 | * |
||
663 | * @param ChildInput $input Object to remove from the list of results |
||
664 | * |
||
665 | * @return $this|ChildInputQuery The current query, for fluid interface |
||
666 | */ |
||
667 | public function prune($input = null) |
||
675 | |||
676 | /** |
||
677 | * Deletes all rows from the input table. |
||
678 | * |
||
679 | * @param ConnectionInterface $con the connection to use |
||
680 | * @return int The number of affected rows (if supported by underlying database driver). |
||
681 | */ |
||
682 | public function doDeleteAll(ConnectionInterface $con = null) |
||
702 | |||
703 | /** |
||
704 | * Performs a DELETE on the database based on the current ModelCriteria |
||
705 | * |
||
706 | * @param ConnectionInterface $con the connection to use |
||
707 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
708 | * if supported by native driver or if emulated using Propel. |
||
709 | * @throws PropelException Any exceptions caught during processing will be |
||
710 | * rethrown wrapped into a PropelException. |
||
711 | */ |
||
712 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
736 | |||
737 | } // InputQuery |
||
738 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.