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 |
||
18 | abstract class AbstractAssetsCommand extends Command implements ContainerAwareInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var SymfonyStyle |
||
22 | */ |
||
23 | protected $io; |
||
24 | |||
25 | /** |
||
26 | * @var boolean |
||
27 | */ |
||
28 | protected $debug = false; |
||
29 | |||
30 | /** |
||
31 | * @var ContainerInterface |
||
32 | */ |
||
33 | protected $container; |
||
34 | |||
35 | /** |
||
36 | * Build tasks from the configuration array. |
||
37 | * |
||
38 | * @param array $configuration |
||
39 | * |
||
40 | * @return Task[] |
||
41 | */ |
||
42 | View Code Duplication | protected function buildTasks(array $configuration) |
|
54 | |||
55 | /** |
||
56 | * Build the filter according to the configuration array. |
||
57 | * |
||
58 | * @param array $configuration |
||
59 | * |
||
60 | * @return FilterInterface[] |
||
61 | */ |
||
62 | View Code Duplication | protected function buildFilters(array $configuration) |
|
74 | |||
75 | /** |
||
76 | * Load the configuration from a yml file. |
||
77 | * |
||
78 | * @param $configurationFile |
||
79 | * |
||
80 | * @return string[] |
||
81 | * |
||
82 | * @throws Exception |
||
83 | */ |
||
84 | protected function loadConfigurationFile($configurationFile) |
||
97 | |||
98 | /** |
||
99 | * Load the configuration from a yml file or the container, according to the given option. |
||
100 | * |
||
101 | * @param InputInterface $input |
||
102 | * @return array |
||
103 | */ |
||
104 | protected function loadConfiguration(InputInterface $input) |
||
116 | |||
117 | /** |
||
118 | * Sets the container. |
||
119 | * |
||
120 | * @param ContainerInterface|null $container A ContainerInterface instance or null |
||
121 | */ |
||
122 | public function setContainer(ContainerInterface $container = null) |
||
126 | } |
||
127 |
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.