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 |
||
27 | class SwitchTask extends AbstractTypo3Task |
||
28 | { |
||
29 | /** |
||
30 | * name |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $name = 'typo3-environment-switch'; |
||
35 | |||
36 | /** |
||
37 | * description |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $description = '[TYPO3] TYPO3 switch environment Localconfiguration.php'; |
||
42 | |||
43 | |||
44 | /** |
||
45 | * execute |
||
46 | * @return bool |
||
47 | * @throws RuntimeException |
||
48 | */ |
||
49 | public function execute(): bool |
||
71 | |||
72 | /** |
||
73 | * moveFile |
||
74 | * |
||
75 | * @param string $from |
||
76 | * @param string $to |
||
77 | * @return void |
||
78 | */ |
||
79 | View Code Duplication | protected function moveFile(string $from, string $to) |
|
88 | |||
89 | /** |
||
90 | * copyFile |
||
91 | * |
||
92 | * @param string $from |
||
93 | * @param string $to |
||
94 | * @return void |
||
95 | */ |
||
96 | View Code Duplication | protected function copyFile(string $from, string $to) |
|
105 | |||
106 | /** |
||
107 | * setPostDeployTask |
||
108 | * |
||
109 | * @return void |
||
110 | */ |
||
111 | protected function setPostDeployTask() |
||
117 | } |
||
118 |
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.