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 | class InnmindNeo4jExtension extends Extension |
||
15 | { |
||
16 | /** |
||
17 | * {@inheritdoc} |
||
18 | */ |
||
19 | 44 | public function load(array $configs, ContainerBuilder $container) |
|
51 | |||
52 | /** |
||
53 | * Inject the defined service in the unit of work |
||
54 | * |
||
55 | * @param ContainerBuilder $container |
||
56 | * @param string $service |
||
57 | * |
||
58 | * @return self |
||
59 | */ |
||
60 | 44 | private function injectPersister( |
|
70 | |||
71 | /** |
||
72 | * Inject value objects to make the connection work |
||
73 | * |
||
74 | * @param ContainerBuilder $container |
||
75 | * @param array $config |
||
76 | * |
||
77 | * @return self |
||
78 | */ |
||
79 | 44 | private function configureConnection( |
|
102 | |||
103 | /** |
||
104 | * Register the classes as added property types |
||
105 | * |
||
106 | * @param ContainerBuilder $container |
||
107 | * @param array $types |
||
108 | * |
||
109 | * @return self |
||
110 | */ |
||
111 | 44 | private function registerTypes( |
|
123 | |||
124 | /** |
||
125 | * Inject the configuration object into the metadata builder |
||
126 | * |
||
127 | * @param ContainerBuilder $container |
||
128 | * @param string $config |
||
129 | * |
||
130 | * @return self |
||
131 | */ |
||
132 | 44 | private function injectMetadataConfiguration( |
|
142 | |||
143 | 44 | View Code Duplication | private function configureGenerators( |
158 | } |
||
159 |
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.