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 | final class PlaceholdersExtension implements Extension |
||
19 | { |
||
20 | |||
21 | const PLACEHOLDERS_REPLACER_ID = 'placeholders.replacer'; |
||
22 | const PLACEHOLDERS_REPOSITIORY_ID = 'placeholders.repository'; |
||
23 | const PLACEHOLDERS_CONTROLLER_ID = 'placeholders.controller'; |
||
24 | const PLACEHOLDERS_TRANSFORMER_ID = 'placeholders.transformer'; |
||
25 | const VARIANTS_PREPROCESSOR_ID = 'placeholders.variants_preprocessor'; |
||
26 | const STEPS_DECORATOR_ID = 'placeholders.steps_decorator'; |
||
27 | const BEFORE_SCENARIO_SUBSCRIBER_ID = 'placeholders.before_scenario'; |
||
28 | const CONTEXT_INITIALIZER_ID = 'placeholders.context_initializer'; |
||
29 | |||
30 | /** |
||
31 | * Returns the extension config key. |
||
32 | * |
||
33 | * @return string |
||
34 | */ |
||
35 | public function getConfigKey() |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | public function process(ContainerBuilder $container) |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | public function initialize(ExtensionManager $extensionManager) |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public function configure(ArrayNodeDefinition $builder) |
||
77 | |||
78 | /** |
||
79 | * Loads extension services into temporary container. |
||
80 | * |
||
81 | * @param ContainerBuilder $container |
||
82 | * @param array $config |
||
83 | */ |
||
84 | public function load(ContainerBuilder $container, array $config) |
||
94 | |||
95 | /** |
||
96 | * @param ContainerBuilder $container |
||
97 | */ |
||
98 | View Code Duplication | private function loadPlaceholdersController(ContainerBuilder $container) |
|
105 | |||
106 | protected function initializePlaceholderUtils($variantTags, $configTags) |
||
111 | |||
112 | |||
113 | /** |
||
114 | * |
||
115 | * @param ContainerBuilder $container |
||
116 | */ |
||
117 | protected function loadPlaceholdersRepository(ContainerBuilder $container, $configs_mapping) |
||
125 | |||
126 | /** |
||
127 | * |
||
128 | * @param ContainerBuilder $container |
||
129 | */ |
||
130 | protected function loadScenarioBranchingFileLoader(ContainerBuilder $container) |
||
139 | |||
140 | |||
141 | /** |
||
142 | * Loads transformers. |
||
143 | * |
||
144 | * @param ContainerBuilder $container |
||
145 | */ |
||
146 | View Code Duplication | protected function loadPlaceholdersTransformer(ContainerBuilder $container) |
|
154 | |||
155 | |||
156 | View Code Duplication | protected function loadStepDecoratingScenarioTester(ContainerBuilder $container) |
|
164 | |||
165 | protected function loadBeforeScenarioSubscriber(ContainerBuilder $container) |
||
171 | |||
172 | View Code Duplication | private function loadContextInitializer(ContainerBuilder $container) |
|
180 | } |
||
181 |
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.