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 |
||
18 | View Code Duplication | class Application extends AdminController |
|
|
|||
19 | { |
||
20 | public $type = 'app'; |
||
21 | |||
22 | /** |
||
23 | * Application constructor. |
||
24 | */ |
||
25 | public function __construct() |
||
30 | |||
31 | /** |
||
32 | * List of all installed applications |
||
33 | * @return string |
||
34 | * @throws \Ffcms\Core\Exception\NativeException |
||
35 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
36 | */ |
||
37 | public function actionIndex() |
||
43 | |||
44 | /** |
||
45 | * Show installation for of applications |
||
46 | * @return string |
||
47 | * @throws \Ffcms\Core\Exception\NativeException |
||
48 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
49 | */ |
||
50 | public function actionInstall() |
||
74 | |||
75 | /** |
||
76 | * Show and process update form for apps |
||
77 | * @param string $sys_name |
||
78 | * @return string |
||
79 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
80 | * @throws \Ffcms\Core\Exception\NativeException |
||
81 | * @throws NotFoundException |
||
82 | */ |
||
83 | public function actionUpdate($sys_name) |
||
107 | |||
108 | /** |
||
109 | * Allow turn on/off applications |
||
110 | * @param $controllerName |
||
111 | * @return string |
||
112 | * @throws \Ffcms\Core\Exception\NativeException |
||
113 | * @throws ForbiddenException |
||
114 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
115 | */ |
||
116 | public function actionTurn($controllerName) |
||
137 | } |
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.