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:
1 | <?php |
||
21 | final class RateFilterUtil |
||
22 | { |
||
23 | use FilterUtilHelper; |
||
24 | |||
25 | private function __construct() { /* noop */ } |
||
26 | |||
27 | /** |
||
28 | * Check if rate matches filters. |
||
29 | * |
||
30 | * @param RateInterface $rate Rate to filter. |
||
31 | * @param array $criteria Filter criteria. |
||
32 | * @return bool TRUE if filter criteria is matched. |
||
33 | */ |
||
34 | 8 | public static function matches(RateInterface $rate, array $criteria) |
|
50 | |||
51 | /** |
||
52 | * Check if date criteria is matched. |
||
53 | * |
||
54 | * @param string $key Date criteria key. |
||
55 | * @param RateInterface $rate Rate to check for match. |
||
56 | * @param array $criteria Filter criterias. |
||
57 | * @return bool TRUE if there is a match. |
||
58 | */ |
||
59 | 8 | private static function matchesDateCriteria($key, RateInterface $rate, array $criteria) |
|
81 | } |
||
82 |
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.