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 |
||
23 | class BackendBootstrap implements BootstrapInterface |
||
24 | { |
||
25 | /** |
||
26 | * Bootstrap method to be called during application bootstrap stage. |
||
27 | * |
||
28 | * @param Application $app the application currently running |
||
29 | */ |
||
30 | public function bootstrap($app) |
||
36 | |||
37 | /** |
||
38 | * Set time base on Option. |
||
39 | * |
||
40 | * @param Application $app the application currently running |
||
41 | */ |
||
42 | View Code Duplication | protected function setTime($app) |
|
51 | |||
52 | /** |
||
53 | * Set theme params |
||
54 | * |
||
55 | * @param Application $app the application currently running |
||
56 | */ |
||
57 | protected function setTheme($app) |
||
69 | |||
70 | /** |
||
71 | * Set modules. |
||
72 | * |
||
73 | * @param Application $app the application currently running |
||
74 | */ |
||
75 | View Code Duplication | protected function setModule($app) |
|
99 | } |
||
100 |
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.