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 |
||
19 | class DependenciesCommand extends Command |
||
20 | { |
||
21 | /** @var ModuleReader */ |
||
22 | private $modulesReader; |
||
23 | |||
24 | /** @var ModulesHelper */ |
||
25 | private $modulesHelper; |
||
26 | |||
27 | /** @var InputHelper */ |
||
28 | private $inputHelper; |
||
29 | |||
30 | View Code Duplication | public function __construct(ModulesHelper $modulesHelper, InputHelper $inputHelper, ModuleReader $modulesReader) |
|
38 | |||
39 | protected function configure() |
||
47 | |||
48 | /** |
||
49 | * @param InputInterface $input |
||
50 | * @param OutputInterface $output |
||
51 | * |
||
52 | * @throws InvalidConfig |
||
53 | * @throws InvalidSchema |
||
54 | * @throws MalformedFile |
||
55 | * |
||
56 | * @return int |
||
57 | */ |
||
58 | protected function execute(InputInterface $input, OutputInterface $output) |
||
75 | |||
76 | /** |
||
77 | * @param DirectedGraph $dependenciesGraph |
||
78 | * @param SymfonyStyle $io |
||
79 | * @param string[] $filters Filtered module names |
||
80 | */ |
||
81 | private function displayModules(DirectedGraph $dependenciesGraph, SymfonyStyle $io, array $filters) |
||
99 | } |
||
100 |
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.