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 |
||
4 | class MicroweberInstaller extends BaseInstaller |
||
5 | { |
||
6 | protected $locations = array( |
||
7 | 'module' => 'userfiles/modules/{$name}/', |
||
8 | 'module-skin' => 'userfiles/modules/{$name}/templates/', |
||
9 | 'template' => 'userfiles/templates/{$name}/', |
||
10 | 'element' => 'userfiles/elements/{$name}/', |
||
11 | 'vendor' => 'vendor/{$name}/', |
||
12 | 'components' => 'components/{$name}/' |
||
13 | ); |
||
14 | |||
15 | /** |
||
16 | * Format package name. |
||
17 | * |
||
18 | * For package type microweber-module, cut off a trailing '-module' if present |
||
19 | * |
||
20 | * For package type microweber-template, cut off a trailing '-template' if present. |
||
21 | * |
||
22 | */ |
||
23 | public function inflectPackageVars($vars) |
||
52 | |||
53 | View Code Duplication | protected function inflectTemplateVars($vars) |
|
60 | |||
61 | View Code Duplication | protected function inflectTemplatesVars($vars) |
|
68 | |||
69 | View Code Duplication | protected function inflectCoreVars($vars) |
|
77 | |||
78 | View Code Duplication | protected function inflectModuleVars($vars) |
|
85 | |||
86 | View Code Duplication | protected function inflectModulesVars($vars) |
|
93 | |||
94 | View Code Duplication | protected function inflectSkinVars($vars) |
|
101 | |||
102 | View Code Duplication | protected function inflectElementVars($vars) |
|
111 | } |
||
112 |
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.