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 |
||
13 | class RemoveByteOrderMarkTransformer implements ResourceTransformerInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $boms; |
||
19 | |||
20 | /** |
||
21 | * Constructor. |
||
22 | */ |
||
23 | 10 | public function __construct() |
|
33 | |||
34 | /** |
||
35 | * @inheritdoc |
||
36 | */ |
||
37 | 10 | View Code Duplication | public function transform(ResourceInterface $resource, ResourceCollection $collection) |
68 | |||
69 | /** |
||
70 | * @inheritdoc |
||
71 | */ |
||
72 | View Code Duplication | public function needsTransforming(ResourceInterface $resource) |
|
83 | |||
84 | /** |
||
85 | * @param string $old |
||
86 | * @param string $new |
||
87 | * |
||
88 | * @throws \RuntimeException |
||
89 | */ |
||
90 | 10 | protected function rename($old, $new) |
|
96 | |||
97 | /** |
||
98 | * @return string |
||
99 | */ |
||
100 | 10 | protected function getBomRegex() |
|
104 | } |
||
105 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.