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 |
||
20 | final class ConvertEventSubscriber implements EventSubscriberInterface |
||
21 | { |
||
22 | /** |
||
23 | * @var string[] |
||
24 | */ |
||
25 | private $addPlaceholderRe = [ |
||
26 | '/^({%\s+block\s+(\w+).+?%})$/m', // {% %} style code |
||
27 | '/^({%\s+endblock\s+%})$/m', // {% %} style code |
||
28 | '/^({{.+?}})$/m', // {{ }} style code |
||
|
|||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * Placeholder text. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | private $placeholder = "\n<div><!-- sculpin-hidden -->$1<!-- /sculpin-hidden --></div>\n"; |
||
37 | |||
38 | /** |
||
39 | * Regex used to remove placeholder. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | private $removePlaceholderRe = "/(\n?<div><!-- sculpin-hidden -->|<!-- \/sculpin-hidden --><\/div>\n|\n?<div><!-- sculpin-hidden -->|<!-- \/sculpin-hidden --><\/div>\n)/m"; |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | public static function getSubscribedEvents() : array |
||
55 | |||
56 | View Code Duplication | public function beforeConvert(ConvertEvent $convertEvent) |
|
67 | |||
68 | View Code Duplication | public function afterConvert(ConvertEvent $convertEvent) |
|
77 | } |
||
78 |
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.