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 LoginController 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 | * @throws Exception |
||
| 65 | * |
||
| 66 | * @return void |
||
| 67 | */ |
||
| 68 | 1 | View Code Duplication | public function getPostLogin() |
| 82 | |||
| 83 | /** |
||
| 84 | * Description. |
||
| 85 | * |
||
| 86 | * @return void |
||
| 87 | */ |
||
| 88 | View Code Duplication | public function getPostReset() |
|
| 102 | |||
| 103 | |||
| 104 | |||
| 105 | /** |
||
| 106 | * Description. |
||
| 107 | * |
||
| 108 | * @throws Exception |
||
| 109 | * |
||
| 110 | * @return void |
||
| 111 | */ |
||
| 112 | 1 | View Code Duplication | public function getPostCreateUser() |
| 126 | } |
||
| 127 |
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.