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 | View Code Duplication | class CriteriaBuilder implements ServiceDefinerInterface |
|
|
|||
15 | { |
||
16 | /** |
||
17 | * @param $contextId |
||
18 | * @param array $contextConfig |
||
19 | * @param ContainerBuilder $container |
||
20 | * |
||
21 | * @return Definition |
||
22 | */ |
||
23 | 4 | public static function defineServices( |
|
32 | |||
33 | /** |
||
34 | * @param $contextId |
||
35 | * @param array $model |
||
36 | * @param ContainerBuilder $container |
||
37 | * |
||
38 | * @return Definition |
||
39 | */ |
||
40 | 4 | private static function defineModel( |
|
82 | |||
83 | /** |
||
84 | * @param string $contextId |
||
85 | * @param array $model |
||
86 | */ |
||
87 | 3 | private static function checkParameters( |
|
100 | |||
101 | /** |
||
102 | * @param ContainerBuilder $container |
||
103 | * @param string $contextId |
||
104 | * @param array $model |
||
105 | */ |
||
106 | 1 | private static function checkServiceExsists( |
|
120 | |||
121 | /** |
||
122 | * @param ContainerBuilder $container |
||
123 | * @param $contextId |
||
124 | * @param $name |
||
125 | */ |
||
126 | 3 | private static function addToCollection( |
|
141 | } |
||
142 |
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.