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 |
||
26 | class ConfigurationProcessor implements ProcessorInterface |
||
27 | { |
||
28 | /** |
||
29 | * @var ContainerBuilder |
||
30 | */ |
||
31 | private $container; |
||
32 | |||
33 | /** |
||
34 | * @var KernelServiceLocator |
||
35 | */ |
||
36 | private $serviceLocator; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | private $envs = array(); |
||
42 | |||
43 | /** |
||
44 | * Constructor. |
||
45 | * |
||
46 | * @param array $envs |
||
47 | */ |
||
48 | public function __construct(array $envs) |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | public function initialize(KernelInterface $kernel) |
||
79 | |||
80 | /** |
||
81 | * Load parameters from config. |
||
82 | * |
||
83 | * @param array $configs |
||
84 | */ |
||
85 | View Code Duplication | private function loadParametersFromConfig(array &$configs) |
|
93 | |||
94 | /** |
||
95 | * Load services from config. |
||
96 | * |
||
97 | * @param array $configs |
||
98 | */ |
||
99 | View Code Duplication | private function loadServicesFromConfig(array &$configs) |
|
106 | |||
107 | /** |
||
108 | * @return ExtensionManager |
||
109 | */ |
||
110 | private function getExtension() |
||
114 | |||
115 | /** |
||
116 | * @return ResourceBuilder |
||
117 | */ |
||
118 | private function getResource() |
||
122 | |||
123 | /** |
||
124 | * @return Configuration |
||
125 | */ |
||
126 | private function getConfiguration() |
||
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.