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 OnceWeekRule implements Rule |
|
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var \DateTime |
||
| 15 | */ |
||
| 16 | private $time; |
||
| 17 | |||
| 18 | 2 | public function __construct() |
|
| 22 | |||
| 23 | /** |
||
| 24 | * @param \DateTimeImmutable $time |
||
| 25 | * |
||
| 26 | * @return bool |
||
| 27 | */ |
||
| 28 | 1 | public function isMatched(\DateTimeImmutable $time) |
|
| 34 | |||
| 35 | /** |
||
| 36 | * @return int |
||
| 37 | */ |
||
| 38 | 2 | public function seconds() |
|
| 45 | } |
||
| 46 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..