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 | abstract class AbstractGenerateCommand extends AbstractCommand |
||
21 | { |
||
22 | /** |
||
23 | * @param InputInterface $input |
||
24 | * @param OutputInterface $output |
||
25 | * @return mixed |
||
26 | */ |
||
27 | abstract public function verify(InputInterface $input, OutputInterface $output); |
||
28 | |||
29 | /** |
||
30 | * addModelArguments |
||
31 | * |
||
32 | * @return self |
||
33 | */ |
||
34 | 14 | View Code Duplication | protected function addModelArgument() |
45 | |||
46 | /** |
||
47 | * Required for correct mock it |
||
48 | * |
||
49 | * @param string $class |
||
50 | * @return mixed |
||
51 | */ |
||
52 | protected function getTemplate($class) |
||
57 | |||
58 | /** |
||
59 | * @return string |
||
60 | */ |
||
61 | 2 | protected function getControllerPath($module, $controller) |
|
68 | |||
69 | /** |
||
70 | * @return string |
||
71 | */ |
||
72 | 1 | protected function getViewPath($module, $controller) |
|
79 | } |
||
80 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.