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 |
||
10 | View Code Duplication | class OnceDayRule extends RuleBase |
|
11 | { |
||
12 | /** |
||
13 | * @var \DateTime |
||
14 | */ |
||
15 | protected $time; |
||
16 | |||
17 | 5 | public function __construct() |
|
21 | |||
22 | /** |
||
23 | * @param \DateTime $time |
||
24 | * |
||
25 | * @return bool |
||
26 | */ |
||
27 | 1 | public function isMatched(\DateTime $time) |
|
33 | |||
34 | /** |
||
35 | * @return int |
||
36 | */ |
||
37 | 2 | public function getSeconds() |
|
45 | } |
||
46 |