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 |
||
11 | class AdminAppController extends AbstractController |
||
12 | { |
||
13 | protected $applications; |
||
14 | protected $application; |
||
15 | |||
16 | /** |
||
17 | * AdminAppController constructor. |
||
18 | * @param bool $checkVersion |
||
19 | * @throws ForbiddenException |
||
20 | */ |
||
21 | public function __construct($checkVersion = true) |
||
45 | |||
46 | /** |
||
47 | * Check if current user can access to admin controllers |
||
48 | */ |
||
49 | private function checkAccess() |
||
70 | |||
71 | /** |
||
72 | * Build application list to memory object |
||
73 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
74 | */ |
||
75 | private function buildApps() |
||
91 | |||
92 | /** |
||
93 | * Get current application data as stdClass object |
||
94 | * @return object|null |
||
95 | */ |
||
96 | public function getAppData() |
||
100 | |||
101 | /** |
||
102 | * Get all applications data as array of objects |
||
103 | * @return array|null |
||
104 | */ |
||
105 | public function getAllApps() |
||
109 | |||
110 | /** |
||
111 | * Get current application configs as array |
||
112 | * @return array |
||
113 | */ |
||
114 | public function getConfigs() |
||
118 | |||
119 | /** |
||
120 | * Save application configs |
||
121 | * @param array $configs |
||
122 | * @return bool |
||
123 | */ |
||
124 | public function setConfigs(array $configs = null) |
||
143 | } |
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.