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 |
||
22 | class UserController implements |
||
23 | ConfigureInterface, |
||
24 | InjectionAwareInterface |
||
25 | { |
||
26 | use ConfigureTrait, InjectionAwareTrait; |
||
27 | |||
28 | /** |
||
29 | * Logout user by setting "user" == null in session. |
||
30 | * |
||
31 | * @return void |
||
32 | */ |
||
33 | public function logout() |
||
38 | |||
39 | |||
40 | /** |
||
41 | * check if user is logged in |
||
42 | * |
||
43 | * @return void |
||
44 | */ |
||
45 | 2 | public function checkIsLogin() |
|
57 | |||
58 | |||
59 | |||
60 | |||
61 | /** |
||
62 | * Description. |
||
63 | * |
||
64 | * @param datatype $variable Description |
||
65 | * |
||
66 | * @throws Exception |
||
67 | * |
||
68 | * @return void |
||
69 | */ |
||
70 | 1 | View Code Duplication | public function getPostLogin() |
84 | |||
85 | /** |
||
86 | * Description. |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | View Code Duplication | public function getPostReset() |
|
104 | |||
105 | |||
106 | |||
107 | /** |
||
108 | * Description. |
||
109 | * |
||
110 | * @param datatype $variable Description |
||
111 | * |
||
112 | * @throws Exception |
||
113 | * |
||
114 | * @return void |
||
115 | */ |
||
116 | 1 | View Code Duplication | public function getPostCreateUser() |
130 | } |
||
131 |
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.