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 |
||
14 | class AdminController extends ProfileController |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * Get all users |
||
19 | * |
||
20 | * |
||
21 | * @return array |
||
22 | */ |
||
23 | 2 | public function getUsers() |
|
34 | |||
35 | /** |
||
36 | * check if user is logged in |
||
37 | * |
||
38 | * @return void |
||
39 | */ |
||
40 | 1 | public function checkIsAdmin() |
|
57 | |||
58 | |||
59 | /** |
||
60 | * Description. |
||
61 | * |
||
62 | * @param datatype $variable Description |
||
63 | * |
||
64 | * @throws Exception |
||
65 | * |
||
66 | * @return void |
||
67 | */ |
||
68 | 1 | public function getUsersIndex() |
|
80 | |||
81 | |||
82 | /** |
||
83 | * Description. |
||
84 | * |
||
85 | * @param datatype $variable Description |
||
86 | * |
||
87 | * @throws Exception |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | 1 | View Code Duplication | public function getPostAdminEditUser($id) |
106 | |||
107 | /** |
||
108 | * Description. |
||
109 | * |
||
110 | * @param datatype $variable Description |
||
111 | * |
||
112 | * @throws Exception |
||
113 | * |
||
114 | * @return void |
||
115 | */ |
||
116 | View Code Duplication | public function getPostAdminCreateUser() |
|
131 | } |
||
132 |
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.