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 |
||
| 8 | class Reporter |
||
| 9 | { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @var Config |
||
| 13 | */ |
||
| 14 | private $config; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var OutputInterface |
||
| 18 | */ |
||
| 19 | private $output; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Reporter constructor. |
||
| 23 | * @param Config $config |
||
| 24 | * @param Output $output |
||
| 25 | */ |
||
| 26 | public function __construct(Config $config, Output $output) |
||
| 31 | |||
| 32 | |||
| 33 | public function generate(Metrics $metrics) |
||
| 50 | } |
||
| 51 |
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..