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 |
||
10 | class Application extends \BFW\Application |
||
11 | { |
||
12 | /** |
||
13 | * @var \BFW\Install\ModuleInstall[] $modulesInstall Modules to install |
||
14 | */ |
||
15 | protected static $modulesInstall = []; |
||
16 | |||
17 | /** |
||
18 | * {@inheritdoc} |
||
19 | */ |
||
20 | protected function initRequest() |
||
24 | |||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | protected function initSession() |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | protected function initErrors() |
||
40 | |||
41 | public static function addModuleInstall(ModuleInstall $module) |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | protected function declareRunSteps() |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | View Code Duplication | public function run() |
|
78 | |||
79 | /** |
||
80 | * Install all modules in the order of the dependency tree. |
||
81 | * |
||
82 | * @return void |
||
83 | */ |
||
84 | protected function installModules() |
||
102 | |||
103 | /** |
||
104 | * Install a module |
||
105 | * |
||
106 | * @param string $moduleName The module name |
||
107 | * |
||
108 | * @return void |
||
109 | */ |
||
110 | protected function installModule($moduleName) |
||
134 | } |
||
135 |
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.