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 |
||
33 | class ConfigurationDebugCommand extends Command |
||
34 | { |
||
35 | /** |
||
36 | * @var SourcesRegistryInterface |
||
37 | */ |
||
38 | protected $sourcesRegistry; |
||
39 | |||
40 | /** |
||
41 | * @var ProcessorsRegistryInterface |
||
42 | */ |
||
43 | protected $processorsRegistry; |
||
44 | |||
45 | /** |
||
46 | * @var RatesConfigurationRegistryInterface |
||
47 | */ |
||
48 | protected $ratesConfigurationRegistry; |
||
49 | |||
50 | /** |
||
51 | * @var RepositoryInterface |
||
52 | */ |
||
53 | protected $repository; |
||
54 | |||
55 | public function __construct( |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | protected function configure() |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | protected function execute(InputInterface $input, OutputInterface $output) |
||
98 | |||
99 | /** |
||
100 | * Display header. |
||
101 | * |
||
102 | * @param OutputInterface $output |
||
103 | * @return ConfigurationDebugCommand $this |
||
104 | */ |
||
105 | protected function displayHeader(OutputInterface $output) |
||
115 | |||
116 | /** |
||
117 | * Display footer. |
||
118 | * |
||
119 | * @param OutputInterface $output |
||
120 | * @return ConfigurationDebugCommand $this |
||
121 | */ |
||
122 | protected function displayFooter(OutputInterface $output) |
||
128 | |||
129 | /** |
||
130 | * Display sources. |
||
131 | * |
||
132 | * @param OutputInterface $output |
||
133 | * @return ConfigurationDebugCommand $this |
||
134 | */ |
||
135 | View Code Duplication | protected function displaySources(OutputInterface $output) |
|
146 | |||
147 | /** |
||
148 | * Display processors. |
||
149 | * |
||
150 | * @param OutputInterface $output |
||
151 | * @return ConfigurationDebugCommand $this |
||
152 | */ |
||
153 | View Code Duplication | protected function displayProcessors(OutputInterface $output) |
|
164 | |||
165 | /** |
||
166 | * Display repository. |
||
167 | * |
||
168 | * @param OutputInterface $output |
||
169 | * @return ConfigurationDebugCommand $this |
||
170 | */ |
||
171 | protected function displayRepository(OutputInterface $output) |
||
177 | |||
178 | /** |
||
179 | * Display rates. |
||
180 | * |
||
181 | * @param OutputInterface $output |
||
182 | * @return ConfigurationDebugCommand $this |
||
183 | */ |
||
184 | protected function displayRates(OutputInterface $output) |
||
208 | |||
209 | /** |
||
210 | * Display new line. |
||
211 | * |
||
212 | * @param OutputInterface $output |
||
213 | * @return ConfigurationDebugCommand $this |
||
214 | */ |
||
215 | protected function displayNewLine(OutputInterface $output) |
||
221 | |||
222 | /** |
||
223 | * Get formatter. |
||
224 | * |
||
225 | * @return FormatterHelper |
||
226 | */ |
||
227 | protected function getFormatter() |
||
231 | } |
||
232 |
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.