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 |
||
22 | class FileSystemLoaderFactory extends AbstractLoaderFactory |
||
23 | { |
||
24 | /** |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | View Code Duplication | public function create(ContainerBuilder $container, $loaderName, array $config) |
|
|
|||
28 | { |
||
29 | $definition = $this->getChildLoaderDefinition(); |
||
30 | $definition->replaceArgument(2, new Reference($this->setupLocator($loaderName, $config, $container))); |
||
31 | |||
32 | return $this->setTaggedLoaderDefinition($loaderName, $definition, $container); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | public function getName() |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | public function addConfiguration(ArrayNodeDefinition $builder) |
||
90 | |||
91 | /* |
||
92 | * @param string[] $staticPaths |
||
93 | * @param array $config |
||
94 | * @param ContainerBuilder $container |
||
95 | * |
||
96 | * @return string[] |
||
97 | */ |
||
98 | private function resolveDataRoots(array $staticPaths, array $config, ContainerBuilder $container) |
||
114 | |||
115 | /** |
||
116 | * @param ContainerBuilder $container |
||
117 | * |
||
118 | * @return string[] |
||
119 | */ |
||
120 | private function getBundleResourcePaths(ContainerBuilder $container) |
||
132 | |||
133 | /** |
||
134 | * @param array[] $metadata |
||
135 | * |
||
136 | * @return string[] |
||
137 | */ |
||
138 | private function getBundlePathsUsingMetadata(array $metadata) |
||
144 | |||
145 | /** |
||
146 | * @param string[] $classes |
||
147 | * |
||
148 | * @return string[] |
||
149 | */ |
||
150 | private function getBundlePathsUsingNamedObj(array $classes) |
||
166 | |||
167 | /** |
||
168 | * @param string $loaderName |
||
169 | * @param array $config |
||
170 | * @param ContainerBuilder $container |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | private function setupLocator($loaderName, array $config, ContainerBuilder $container) |
||
184 | |||
185 | /** |
||
186 | * @param array $config |
||
187 | * |
||
188 | * @return Definition |
||
189 | */ |
||
190 | private function getLocatorDefinition(array $config) |
||
198 | } |
||
199 |
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.