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 |
||
14 | final class PimpleContainerAdapter implements ContainerAdapter |
||
15 | { |
||
16 | /** |
||
17 | * @var Container |
||
18 | */ |
||
19 | private $container; |
||
20 | |||
21 | /** |
||
22 | * @param Container $container |
||
23 | */ |
||
24 | public function setContainer($container) |
||
28 | |||
29 | public function addApplicationConfig(ApplicationConfig $config, $prefix = 'config') |
||
41 | |||
42 | public function addServiceConfig(ServiceConfig $config) |
||
48 | |||
49 | /** |
||
50 | * @throws UnsupportedFeatureException |
||
51 | */ |
||
52 | public function addInflectorConfig(InflectorConfig $config) |
||
56 | |||
57 | private function addServiceToContainer(ServiceDefinition $definition) |
||
67 | |||
68 | /** |
||
69 | * @param ServiceDefinition $definition |
||
70 | * |
||
71 | * @return \Closure |
||
72 | */ |
||
73 | private function createFactory(ServiceDefinition $definition) |
||
85 | |||
86 | /** |
||
87 | * @param ServiceDefinition $definition |
||
88 | * |
||
89 | * @return \Closure |
||
90 | */ |
||
91 | View Code Duplication | private function createFactoryFactory(ServiceDefinition $definition) |
|
100 | |||
101 | /** |
||
102 | * @param ServiceDefinition $definition |
||
103 | * |
||
104 | * @return \Closure |
||
105 | */ |
||
106 | private function createAliasFactory(ServiceDefinition $definition) |
||
112 | |||
113 | /** |
||
114 | * @param ServiceDefinition $definition |
||
115 | * |
||
116 | * @return \Closure |
||
117 | */ |
||
118 | private function createInstanceFactory(ServiceDefinition $definition) |
||
131 | |||
132 | /** |
||
133 | * @param array $arguments |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | private function resolveArguments(array $arguments) |
||
154 | } |
||
155 |
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.