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 |
||
17 | class UserController implements |
||
18 | ConfigureInterface, |
||
19 | InjectionAwareInterface |
||
20 | { |
||
21 | use ConfigureTrait, |
||
22 | InjectionAwareTrait; |
||
23 | |||
24 | |||
25 | |||
26 | /** |
||
27 | * @var $data description |
||
28 | */ |
||
29 | //private $data; |
||
30 | |||
31 | |||
32 | |||
33 | /** |
||
34 | * Description. |
||
35 | * |
||
36 | * @param datatype $variable Description |
||
|
|||
37 | * |
||
38 | * @throws Exception |
||
39 | * |
||
40 | * @return void |
||
41 | */ |
||
42 | public function getIndex() |
||
63 | |||
64 | |||
65 | |||
66 | /** |
||
67 | * Description. |
||
68 | * |
||
69 | * @param datatype $variable Description |
||
70 | * |
||
71 | * @throws Exception |
||
72 | * |
||
73 | * @return void |
||
74 | */ |
||
75 | View Code Duplication | public function getPostLogin() |
|
92 | |||
93 | |||
94 | |||
95 | /** |
||
96 | * Description. |
||
97 | * |
||
98 | * @param datatype $variable Description |
||
99 | * |
||
100 | * @throws Exception |
||
101 | * |
||
102 | * @return void |
||
103 | */ |
||
104 | View Code Duplication | public function getPostCreateUser() |
|
121 | |||
122 | /** |
||
123 | * Handler with form to update an item. |
||
124 | * |
||
125 | * @return void |
||
126 | */ |
||
127 | View Code Duplication | public function getPostUpdateUser($id) |
|
144 | |||
145 | /** |
||
146 | * Logout the user |
||
147 | * |
||
148 | * @return void |
||
149 | */ |
||
150 | public function logoutUser() |
||
155 | |||
156 | /** |
||
157 | * Render admin page with all users |
||
158 | * |
||
159 | * @return void |
||
160 | */ |
||
161 | public function getAdminIndex() |
||
182 | |||
183 | /** |
||
184 | * Delete a user |
||
185 | * |
||
186 | *@var integer id of user to delete |
||
187 | * |
||
188 | * @return void |
||
189 | */ |
||
190 | public function adminDeleteUser($id) |
||
201 | } |
||
202 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.