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 |
||
14 | class GenerateSeedCommand extends Command |
||
15 | { |
||
16 | /** |
||
17 | * Configuration of command |
||
18 | */ |
||
19 | protected function configure() |
||
26 | |||
27 | /** |
||
28 | * Execute method of command |
||
29 | * @param InputInterface $input |
||
30 | * @param OutputInterface $output |
||
31 | * |
||
32 | * @return int|null|void |
||
33 | * @throws \Exception |
||
34 | */ |
||
35 | View Code Duplication | protected function execute(InputInterface $input, OutputInterface $output) |
|
64 | |||
65 | /** |
||
66 | * Generate code |
||
67 | * |
||
68 | * @param array $placeHolders |
||
69 | * @param array $replacements |
||
70 | * @param string $templateName |
||
71 | * @param string $resultPath |
||
72 | * @return bool|int |
||
73 | */ |
||
74 | View Code Duplication | public function generateCode($placeHolders, $replacements, $templateName, $resultPath) |
|
87 | |||
88 | /** |
||
89 | * @param string $seedName |
||
90 | * @return string |
||
91 | * @throws \Exception |
||
92 | */ |
||
93 | View Code Duplication | private function getPathForSeed($seedName) |
|
104 | } |
||
105 |
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.