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 |
||
11 | View Code Duplication | class HolidayRule implements HourIntervalRule |
|
12 | { |
||
13 | use HourlyIntervalRuleTrait; |
||
14 | use RandSecondsRuleTrait; |
||
15 | |||
16 | /** |
||
17 | * @param int $start |
||
18 | * @param int $end |
||
19 | * @param int $seconds |
||
20 | */ |
||
21 | 11 | public function __construct($start, $end, $seconds) |
|
27 | |||
28 | /** |
||
29 | * @param \DateTimeImmutable $time |
||
30 | * |
||
31 | * @return bool |
||
32 | */ |
||
33 | 11 | public function isMatched(\DateTimeImmutable $time) |
|
41 | } |
||
42 |