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 |
||
8 | class Application extends \BFW\Application |
||
9 | { |
||
10 | protected static $modulesInstances = []; |
||
11 | |||
12 | /** |
||
13 | * {@inheritdoc} |
||
14 | */ |
||
15 | protected function initRequest() |
||
19 | |||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | protected function initSession() |
||
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | protected function initErrors() |
||
35 | |||
36 | public static function addModuleInstallInstance( |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | protected function declareRunPhases() |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | View Code Duplication | public function run() |
|
74 | |||
75 | protected function installModules() |
||
93 | |||
94 | protected function installModule($moduleName) |
||
118 | } |
||
119 |
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.