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 SubscriptionQuery 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 SubscriptionQuery, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
122 | abstract class SubscriptionQuery extends ModelCriteria |
||
123 | { |
||
124 | protected $entityNotFoundExceptionClass = '\\Propel\\Runtime\\Exception\\EntityNotFoundException'; |
||
125 | |||
126 | /** |
||
127 | * Initializes internal state of \Jalle19\StatusManager\Database\Base\SubscriptionQuery object. |
||
128 | * |
||
129 | * @param string $dbName The database name |
||
130 | * @param string $modelName The phpName of a model, e.g. 'Book' |
||
131 | * @param string $modelAlias The alias for the model in this query, e.g. 'b' |
||
132 | */ |
||
133 | public function __construct($dbName = 'tvheadend_status_manager', $modelName = '\\Jalle19\\StatusManager\\Database\\Subscription', $modelAlias = null) |
||
137 | |||
138 | /** |
||
139 | * Returns a new ChildSubscriptionQuery object. |
||
140 | * |
||
141 | * @param string $modelAlias The alias of a model in the query |
||
142 | * @param Criteria $criteria Optional Criteria to build the query from |
||
143 | * |
||
144 | * @return ChildSubscriptionQuery |
||
145 | */ |
||
146 | View Code Duplication | public static function create($modelAlias = null, Criteria $criteria = null) |
|
161 | |||
162 | /** |
||
163 | * Find object by primary key. |
||
164 | * Propel uses the instance pool to skip the database if the object exists. |
||
165 | * Go fast if the query is untouched. |
||
166 | * |
||
167 | * <code> |
||
168 | * $obj = $c->findPk(12, $con); |
||
169 | * </code> |
||
170 | * |
||
171 | * @param mixed $key Primary key to use for the query |
||
172 | * @param ConnectionInterface $con an optional connection object |
||
173 | * |
||
174 | * @return ChildSubscription|array|mixed the result, formatted by the current formatter |
||
175 | */ |
||
176 | View Code Duplication | public function findPk($key, ConnectionInterface $con = null) |
|
197 | |||
198 | /** |
||
199 | * Find object by primary key using raw SQL to go fast. |
||
200 | * Bypass doSelect() and the object formatter by using generated code. |
||
201 | * |
||
202 | * @param mixed $key Primary key to use for the query |
||
203 | * @param ConnectionInterface $con A connection object |
||
204 | * |
||
205 | * @throws \Propel\Runtime\Exception\PropelException |
||
206 | * |
||
207 | * @return ChildSubscription A model object, or null if the key is not found |
||
208 | */ |
||
209 | View Code Duplication | protected function findPkSimple($key, ConnectionInterface $con) |
|
231 | |||
232 | /** |
||
233 | * Find object by primary key. |
||
234 | * |
||
235 | * @param mixed $key Primary key to use for the query |
||
236 | * @param ConnectionInterface $con A connection object |
||
237 | * |
||
238 | * @return ChildSubscription|array|mixed the result, formatted by the current formatter |
||
239 | */ |
||
240 | View Code Duplication | protected function findPkComplex($key, ConnectionInterface $con) |
|
250 | |||
251 | /** |
||
252 | * Find objects by primary key |
||
253 | * <code> |
||
254 | * $objs = $c->findPks(array(12, 56, 832), $con); |
||
255 | * </code> |
||
256 | * @param array $keys Primary keys to use for the query |
||
257 | * @param ConnectionInterface $con an optional connection object |
||
258 | * |
||
259 | * @return ObjectCollection|array|mixed the list of results, formatted by the current formatter |
||
260 | */ |
||
261 | View Code Duplication | public function findPks($keys, ConnectionInterface $con = null) |
|
274 | |||
275 | /** |
||
276 | * Filter the query by primary key |
||
277 | * |
||
278 | * @param mixed $key Primary key to use for the query |
||
279 | * |
||
280 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
281 | */ |
||
282 | public function filterByPrimaryKey($key) |
||
287 | |||
288 | /** |
||
289 | * Filter the query by a list of primary keys |
||
290 | * |
||
291 | * @param array $keys The list of primary key to use for the query |
||
292 | * |
||
293 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
294 | */ |
||
295 | public function filterByPrimaryKeys($keys) |
||
300 | |||
301 | /** |
||
302 | * Filter the query on the id column |
||
303 | * |
||
304 | * Example usage: |
||
305 | * <code> |
||
306 | * $query->filterById(1234); // WHERE id = 1234 |
||
307 | * $query->filterById(array(12, 34)); // WHERE id IN (12, 34) |
||
308 | * $query->filterById(array('min' => 12)); // WHERE id > 12 |
||
309 | * </code> |
||
310 | * |
||
311 | * @param mixed $id 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|ChildSubscriptionQuery The current query, for fluid interface |
||
318 | */ |
||
319 | View Code Duplication | public function filterById($id = null, $comparison = null) |
|
341 | |||
342 | /** |
||
343 | * Filter the query on the instance_name column |
||
344 | * |
||
345 | * Example usage: |
||
346 | * <code> |
||
347 | * $query->filterByInstanceName('fooValue'); // WHERE instance_name = 'fooValue' |
||
348 | * $query->filterByInstanceName('%fooValue%'); // WHERE instance_name LIKE '%fooValue%' |
||
349 | * </code> |
||
350 | * |
||
351 | * @param string $instanceName The value to use as filter. |
||
352 | * Accepts wildcards (* and % trigger a LIKE) |
||
353 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
354 | * |
||
355 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
356 | */ |
||
357 | View Code Duplication | public function filterByInstanceName($instanceName = null, $comparison = null) |
|
370 | |||
371 | /** |
||
372 | * Filter the query on the user_id column |
||
373 | * |
||
374 | * Example usage: |
||
375 | * <code> |
||
376 | * $query->filterByUserId(1234); // WHERE user_id = 1234 |
||
377 | * $query->filterByUserId(array(12, 34)); // WHERE user_id IN (12, 34) |
||
378 | * $query->filterByUserId(array('min' => 12)); // WHERE user_id > 12 |
||
379 | * </code> |
||
380 | * |
||
381 | * @see filterByUser() |
||
382 | * |
||
383 | * @param mixed $userId The value to use as filter. |
||
384 | * Use scalar values for equality. |
||
385 | * Use array values for in_array() equivalent. |
||
386 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
387 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
388 | * |
||
389 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
390 | */ |
||
391 | View Code Duplication | public function filterByUserId($userId = null, $comparison = null) |
|
413 | |||
414 | /** |
||
415 | * Filter the query on the channel_id column |
||
416 | * |
||
417 | * Example usage: |
||
418 | * <code> |
||
419 | * $query->filterByChannelId(1234); // WHERE channel_id = 1234 |
||
420 | * $query->filterByChannelId(array(12, 34)); // WHERE channel_id IN (12, 34) |
||
421 | * $query->filterByChannelId(array('min' => 12)); // WHERE channel_id > 12 |
||
422 | * </code> |
||
423 | * |
||
424 | * @see filterByChannel() |
||
425 | * |
||
426 | * @param mixed $channelId The value to use as filter. |
||
427 | * Use scalar values for equality. |
||
428 | * Use array values for in_array() equivalent. |
||
429 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
430 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
431 | * |
||
432 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
433 | */ |
||
434 | View Code Duplication | public function filterByChannelId($channelId = null, $comparison = null) |
|
456 | |||
457 | /** |
||
458 | * Filter the query on the subscription_id column |
||
459 | * |
||
460 | * Example usage: |
||
461 | * <code> |
||
462 | * $query->filterBySubscriptionId(1234); // WHERE subscription_id = 1234 |
||
463 | * $query->filterBySubscriptionId(array(12, 34)); // WHERE subscription_id IN (12, 34) |
||
464 | * $query->filterBySubscriptionId(array('min' => 12)); // WHERE subscription_id > 12 |
||
465 | * </code> |
||
466 | * |
||
467 | * @param mixed $subscriptionId The value to use as filter. |
||
468 | * Use scalar values for equality. |
||
469 | * Use array values for in_array() equivalent. |
||
470 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
471 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
472 | * |
||
473 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
474 | */ |
||
475 | View Code Duplication | public function filterBySubscriptionId($subscriptionId = null, $comparison = null) |
|
497 | |||
498 | /** |
||
499 | * Filter the query on the started column |
||
500 | * |
||
501 | * Example usage: |
||
502 | * <code> |
||
503 | * $query->filterByStarted('2011-03-14'); // WHERE started = '2011-03-14' |
||
504 | * $query->filterByStarted('now'); // WHERE started = '2011-03-14' |
||
505 | * $query->filterByStarted(array('max' => 'yesterday')); // WHERE started > '2011-03-13' |
||
506 | * </code> |
||
507 | * |
||
508 | * @param mixed $started The value to use as filter. |
||
509 | * Values can be integers (unix timestamps), DateTime objects, or strings. |
||
510 | * Empty strings are treated as NULL. |
||
511 | * Use scalar values for equality. |
||
512 | * Use array values for in_array() equivalent. |
||
513 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
514 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
515 | * |
||
516 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
517 | */ |
||
518 | View Code Duplication | public function filterByStarted($started = null, $comparison = null) |
|
540 | |||
541 | /** |
||
542 | * Filter the query on the stopped column |
||
543 | * |
||
544 | * Example usage: |
||
545 | * <code> |
||
546 | * $query->filterByStopped('2011-03-14'); // WHERE stopped = '2011-03-14' |
||
547 | * $query->filterByStopped('now'); // WHERE stopped = '2011-03-14' |
||
548 | * $query->filterByStopped(array('max' => 'yesterday')); // WHERE stopped > '2011-03-13' |
||
549 | * </code> |
||
550 | * |
||
551 | * @param mixed $stopped The value to use as filter. |
||
552 | * Values can be integers (unix timestamps), DateTime objects, or strings. |
||
553 | * Empty strings are treated as NULL. |
||
554 | * Use scalar values for equality. |
||
555 | * Use array values for in_array() equivalent. |
||
556 | * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals. |
||
557 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
558 | * |
||
559 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
560 | */ |
||
561 | View Code Duplication | public function filterByStopped($stopped = null, $comparison = null) |
|
583 | |||
584 | /** |
||
585 | * Filter the query on the title column |
||
586 | * |
||
587 | * Example usage: |
||
588 | * <code> |
||
589 | * $query->filterByTitle('fooValue'); // WHERE title = 'fooValue' |
||
590 | * $query->filterByTitle('%fooValue%'); // WHERE title LIKE '%fooValue%' |
||
591 | * </code> |
||
592 | * |
||
593 | * @param string $title The value to use as filter. |
||
594 | * Accepts wildcards (* and % trigger a LIKE) |
||
595 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
596 | * |
||
597 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
598 | */ |
||
599 | View Code Duplication | public function filterByTitle($title = null, $comparison = null) |
|
612 | |||
613 | /** |
||
614 | * Filter the query on the service column |
||
615 | * |
||
616 | * Example usage: |
||
617 | * <code> |
||
618 | * $query->filterByService('fooValue'); // WHERE service = 'fooValue' |
||
619 | * $query->filterByService('%fooValue%'); // WHERE service LIKE '%fooValue%' |
||
620 | * </code> |
||
621 | * |
||
622 | * @param string $service The value to use as filter. |
||
623 | * Accepts wildcards (* and % trigger a LIKE) |
||
624 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
625 | * |
||
626 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
627 | */ |
||
628 | View Code Duplication | public function filterByService($service = null, $comparison = null) |
|
641 | |||
642 | /** |
||
643 | * Filter the query by a related \Jalle19\StatusManager\Database\Instance object |
||
644 | * |
||
645 | * @param \Jalle19\StatusManager\Database\Instance|ObjectCollection $instance The related object(s) to use as filter |
||
646 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
647 | * |
||
648 | * @throws \Propel\Runtime\Exception\PropelException |
||
649 | * |
||
650 | * @return ChildSubscriptionQuery The current query, for fluid interface |
||
651 | */ |
||
652 | View Code Duplication | public function filterByInstance($instance, $comparison = null) |
|
668 | |||
669 | /** |
||
670 | * Adds a JOIN clause to the query using the Instance relation |
||
671 | * |
||
672 | * @param string $relationAlias optional alias for the relation |
||
673 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
674 | * |
||
675 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
676 | */ |
||
677 | View Code Duplication | public function joinInstance($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
|
700 | |||
701 | /** |
||
702 | * Use the Instance relation Instance object |
||
703 | * |
||
704 | * @see useQuery() |
||
705 | * |
||
706 | * @param string $relationAlias optional alias for the relation, |
||
707 | * to be used as main alias in the secondary query |
||
708 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
709 | * |
||
710 | * @return \Jalle19\StatusManager\Database\InstanceQuery A secondary query class using the current class as primary query |
||
711 | */ |
||
712 | public function useInstanceQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
||
718 | |||
719 | /** |
||
720 | * Filter the query by a related \Jalle19\StatusManager\Database\User object |
||
721 | * |
||
722 | * @param \Jalle19\StatusManager\Database\User|ObjectCollection $user The related object(s) to use as filter |
||
723 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
724 | * |
||
725 | * @throws \Propel\Runtime\Exception\PropelException |
||
726 | * |
||
727 | * @return ChildSubscriptionQuery The current query, for fluid interface |
||
728 | */ |
||
729 | View Code Duplication | public function filterByUser($user, $comparison = null) |
|
745 | |||
746 | /** |
||
747 | * Adds a JOIN clause to the query using the User relation |
||
748 | * |
||
749 | * @param string $relationAlias optional alias for the relation |
||
750 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
751 | * |
||
752 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
753 | */ |
||
754 | View Code Duplication | public function joinUser($relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
|
777 | |||
778 | /** |
||
779 | * Use the User relation User object |
||
780 | * |
||
781 | * @see useQuery() |
||
782 | * |
||
783 | * @param string $relationAlias optional alias for the relation, |
||
784 | * to be used as main alias in the secondary query |
||
785 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
786 | * |
||
787 | * @return \Jalle19\StatusManager\Database\UserQuery A secondary query class using the current class as primary query |
||
788 | */ |
||
789 | public function useUserQuery($relationAlias = null, $joinType = Criteria::LEFT_JOIN) |
||
795 | |||
796 | /** |
||
797 | * Filter the query by a related \Jalle19\StatusManager\Database\Channel object |
||
798 | * |
||
799 | * @param \Jalle19\StatusManager\Database\Channel|ObjectCollection $channel The related object(s) to use as filter |
||
800 | * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL |
||
801 | * |
||
802 | * @throws \Propel\Runtime\Exception\PropelException |
||
803 | * |
||
804 | * @return ChildSubscriptionQuery The current query, for fluid interface |
||
805 | */ |
||
806 | View Code Duplication | public function filterByChannel($channel, $comparison = null) |
|
822 | |||
823 | /** |
||
824 | * Adds a JOIN clause to the query using the Channel relation |
||
825 | * |
||
826 | * @param string $relationAlias optional alias for the relation |
||
827 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
828 | * |
||
829 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
830 | */ |
||
831 | View Code Duplication | public function joinChannel($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
|
854 | |||
855 | /** |
||
856 | * Use the Channel relation Channel object |
||
857 | * |
||
858 | * @see useQuery() |
||
859 | * |
||
860 | * @param string $relationAlias optional alias for the relation, |
||
861 | * to be used as main alias in the secondary query |
||
862 | * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' |
||
863 | * |
||
864 | * @return \Jalle19\StatusManager\Database\ChannelQuery A secondary query class using the current class as primary query |
||
865 | */ |
||
866 | public function useChannelQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN) |
||
872 | |||
873 | /** |
||
874 | * Exclude object from result |
||
875 | * |
||
876 | * @param ChildSubscription $subscription Object to remove from the list of results |
||
877 | * |
||
878 | * @return $this|ChildSubscriptionQuery The current query, for fluid interface |
||
879 | */ |
||
880 | public function prune($subscription = null) |
||
888 | |||
889 | /** |
||
890 | * Deletes all rows from the subscription table. |
||
891 | * |
||
892 | * @param ConnectionInterface $con the connection to use |
||
893 | * @return int The number of affected rows (if supported by underlying database driver). |
||
894 | */ |
||
895 | View Code Duplication | public function doDeleteAll(ConnectionInterface $con = null) |
|
915 | |||
916 | /** |
||
917 | * Performs a DELETE on the database based on the current ModelCriteria |
||
918 | * |
||
919 | * @param ConnectionInterface $con the connection to use |
||
920 | * @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows |
||
921 | * if supported by native driver or if emulated using Propel. |
||
922 | * @throws PropelException Any exceptions caught during processing will be |
||
923 | * rethrown wrapped into a PropelException. |
||
924 | */ |
||
925 | View Code Duplication | public function delete(ConnectionInterface $con = null) |
|
949 | |||
950 | } // SubscriptionQuery |
||
951 |
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.