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 GenerateCommandCommand extends Command |
||
14 | { |
||
15 | /** |
||
16 | * Configuration of command |
||
17 | */ |
||
18 | protected function configure() |
||
26 | |||
27 | /** |
||
28 | * Execute method of command |
||
29 | * |
||
30 | * @param InputInterface $input |
||
31 | * @param OutputInterface $output |
||
32 | * |
||
33 | * @return void |
||
34 | * @throws \Exception |
||
35 | */ |
||
36 | protected function execute(InputInterface $input, OutputInterface $output) |
||
72 | |||
73 | /** |
||
74 | * Generate code |
||
75 | * |
||
76 | * @param array $placeHolders |
||
77 | * @param array $replacements |
||
78 | * @param string $templateName |
||
79 | * @param string $resultPath |
||
80 | * @return bool|int |
||
81 | */ |
||
82 | View Code Duplication | public function generateCode($placeHolders, $replacements, $templateName, $resultPath) |
|
95 | |||
96 | /** |
||
97 | * @param string $commandClass |
||
98 | * @return string |
||
99 | * @throws \Exception |
||
100 | */ |
||
101 | private function getPathForCommand($commandClass) |
||
110 | |||
111 | /** |
||
112 | * Colonize command name |
||
113 | * |
||
114 | * @param $word |
||
115 | * @return string |
||
116 | */ |
||
117 | private function colonize($word) |
||
125 | } |
||
126 |
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.