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 |
||
15 | class MetadataDrivers implements ServiceLoaderInterface |
||
16 | { |
||
17 | /** |
||
18 | * Creates the file locator service definition. |
||
19 | * |
||
20 | * @param string $modelDir |
||
21 | * @param string $mixinDir |
||
22 | * @return Definition |
||
23 | */ |
||
24 | private function createFileLocator($modelDir, $mixinDir) |
||
33 | |||
34 | /** |
||
35 | * Creates the YAML metadata driver service definition. |
||
36 | * |
||
37 | * @param string $driverName |
||
38 | * @param array $driverConfig |
||
39 | * @param ContainerBuilder $container |
||
40 | * @return Definition |
||
41 | */ |
||
42 | private function createYmlDriver($driverName, array $driverConfig, ContainerBuilder $container) |
||
65 | |||
66 | /** |
||
67 | * Gets the directory for a definition type. |
||
68 | * |
||
69 | * @param string $type |
||
70 | * @param array $driverConfig |
||
71 | * @param ContainerBuilder $container |
||
72 | * @return string |
||
73 | */ |
||
74 | private function getDefinitionDir($type, array $driverConfig, ContainerBuilder $container) |
||
86 | |||
87 | /** |
||
88 | * Gets the definition directories for models and mixins and returns as a tuple. |
||
89 | * |
||
90 | * @param array $driverConfig |
||
91 | * @param ContainerBuilder $container |
||
92 | * @return string[] |
||
93 | */ |
||
94 | private function getDefinitionDirs(array $driverConfig, ContainerBuilder $container) |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | * @todo Add low-level support for multiple drivers in the metadata factory. |
||
104 | */ |
||
105 | View Code Duplication | public function load(array $config, ContainerBuilder $container) |
|
130 | } |
||
131 |
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.