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 | class UserController implements |
||
19 | ConfigureInterface, |
||
20 | InjectionAwareInterface |
||
21 | { |
||
22 | use ConfigureTrait, |
||
23 | InjectionAwareTrait; |
||
24 | |||
25 | |||
26 | /** |
||
27 | * @var $data description |
||
28 | */ |
||
29 | //private $data; |
||
30 | |||
31 | |||
32 | /** |
||
33 | * Handler with form to login user |
||
34 | * |
||
35 | * @return void |
||
36 | */ |
||
37 | public function getPostLogin() |
||
54 | |||
55 | |||
56 | // Handle user logout |
||
57 | public function getLogout() |
||
62 | |||
63 | |||
64 | /** |
||
65 | * Handler with form to register new user |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | public function getPostRegister() |
||
86 | |||
87 | |||
88 | // Handle user profile page |
||
89 | public function getProfile($id) |
||
107 | |||
108 | |||
109 | View Code Duplication | public function getPostUpdate() |
|
127 | } |
||
128 |
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.