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 |
||
| 15 | class UserController implements |
||
| 16 | ConfigureInterface, |
||
| 17 | InjectionAwareInterface |
||
| 18 | { |
||
| 19 | use ConfigureTrait, |
||
| 20 | InjectionAwareTrait; |
||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | /** |
||
| 25 | * Protected variables |
||
| 26 | */ |
||
| 27 | protected $view; |
||
| 28 | protected $pageRender; |
||
| 29 | protected $request; |
||
| 30 | protected $response; |
||
| 31 | protected $session; |
||
| 32 | |||
| 33 | |||
| 34 | /** |
||
| 35 | * Set services to variables |
||
| 36 | * |
||
| 37 | */ |
||
| 38 | public function setUp() |
||
| 46 | |||
| 47 | |||
| 48 | /** |
||
| 49 | * Description. |
||
| 50 | * |
||
| 51 | * @param datatype $variable Description |
||
|
|
|||
| 52 | * |
||
| 53 | * @throws Exception |
||
| 54 | * |
||
| 55 | * @return void |
||
| 56 | */ |
||
| 57 | View Code Duplication | public function getIndex() |
|
| 66 | |||
| 67 | |||
| 68 | /** |
||
| 69 | * Description. |
||
| 70 | * |
||
| 71 | * @param datatype $variable Description |
||
| 72 | * |
||
| 73 | * @throws Exception |
||
| 74 | * |
||
| 75 | * @return void |
||
| 76 | */ |
||
| 77 | View Code Duplication | public function getLogin() |
|
| 86 | |||
| 87 | |||
| 88 | /** |
||
| 89 | * Description. |
||
| 90 | * |
||
| 91 | * @param datatype $variable Description |
||
| 92 | * |
||
| 93 | * @throws Exception |
||
| 94 | * |
||
| 95 | * @return void |
||
| 96 | */ |
||
| 97 | View Code Duplication | public function getCreateUser($message = null) |
|
| 106 | |||
| 107 | |||
| 108 | /** |
||
| 109 | * Description. |
||
| 110 | * |
||
| 111 | * @param datatype $variable Description |
||
| 112 | * |
||
| 113 | * @throws Exception |
||
| 114 | * |
||
| 115 | * @return void |
||
| 116 | */ |
||
| 117 | public function postCreatingUser() |
||
| 146 | |||
| 147 | |||
| 148 | /** |
||
| 149 | * Description. |
||
| 150 | * |
||
| 151 | * @param datatype $variable Description |
||
| 152 | * |
||
| 153 | * @throws Exception |
||
| 154 | * |
||
| 155 | * @return void |
||
| 156 | */ |
||
| 157 | public function getUserProfile() |
||
| 170 | |||
| 171 | |||
| 172 | /** |
||
| 173 | * Description. |
||
| 174 | * |
||
| 175 | * @param datatype $variable Description |
||
| 176 | * |
||
| 177 | * @throws Exception |
||
| 178 | * |
||
| 179 | * @return void |
||
| 180 | */ |
||
| 181 | public function validateUser() |
||
| 218 | |||
| 219 | |||
| 220 | /** |
||
| 221 | * Description. |
||
| 222 | * |
||
| 223 | * @param datatype $variable Description |
||
| 224 | * |
||
| 225 | * @throws Exception |
||
| 226 | * |
||
| 227 | * @return void |
||
| 228 | */ |
||
| 229 | View Code Duplication | public function updateGetUserProfile($message = null) |
|
| 242 | |||
| 243 | |||
| 244 | /** |
||
| 245 | * Description. |
||
| 246 | * |
||
| 247 | * @param datatype $variable Description |
||
| 248 | * |
||
| 249 | * @throws Exception |
||
| 250 | * |
||
| 251 | * @return void |
||
| 252 | */ |
||
| 253 | public function updatePostUserProfile() |
||
| 276 | |||
| 277 | |||
| 278 | /** |
||
| 279 | * Description. |
||
| 280 | * |
||
| 281 | * @param datatype $variable Description |
||
| 282 | * |
||
| 283 | * @throws Exception |
||
| 284 | * |
||
| 285 | * @return void |
||
| 286 | */ |
||
| 287 | public function getLogout() |
||
| 293 | |||
| 294 | |||
| 295 | /** |
||
| 296 | * Description. |
||
| 297 | * |
||
| 298 | * @param datatype $variable Description |
||
| 299 | * |
||
| 300 | * @throws Exception |
||
| 301 | * |
||
| 302 | * @return void |
||
| 303 | */ |
||
| 304 | public function getAdmin() |
||
| 316 | |||
| 317 | |||
| 318 | /** |
||
| 319 | * Description. |
||
| 320 | * |
||
| 321 | * @param datatype $variable Description |
||
| 322 | * |
||
| 323 | * @throws Exception |
||
| 324 | * |
||
| 325 | * @return void |
||
| 326 | */ |
||
| 327 | View Code Duplication | public function getAdminUpdateUser($message = "", $userId = null) |
|
| 341 | |||
| 342 | |||
| 343 | /** |
||
| 344 | * Description. |
||
| 345 | * |
||
| 346 | * @param datatype $variable Description |
||
| 347 | * |
||
| 348 | * @throws Exception |
||
| 349 | * |
||
| 350 | * @return void |
||
| 351 | */ |
||
| 352 | View Code Duplication | public function postAdminUpdateUser() |
|
| 374 | |||
| 375 | |||
| 376 | /** |
||
| 377 | * Description. |
||
| 378 | * |
||
| 379 | * @param datatype $variable Description |
||
| 380 | * |
||
| 381 | * @throws Exception |
||
| 382 | * |
||
| 383 | * @return void |
||
| 384 | */ |
||
| 385 | View Code Duplication | public function getAdminCreateUser($message = null) |
|
| 394 | |||
| 395 | |||
| 396 | /** |
||
| 397 | * Description. |
||
| 398 | * |
||
| 399 | * @param datatype $variable Description |
||
| 400 | * |
||
| 401 | * @throws Exception |
||
| 402 | * |
||
| 403 | * @return void |
||
| 404 | */ |
||
| 405 | View Code Duplication | public function postAdminCreateUser() |
|
| 429 | |||
| 430 | |||
| 431 | /** |
||
| 432 | * Description. |
||
| 433 | * |
||
| 434 | * @param datatype $variable Description |
||
| 435 | * |
||
| 436 | * @throws Exception |
||
| 437 | * |
||
| 438 | * @return void |
||
| 439 | */ |
||
| 440 | public function getAdminDeleteUser() |
||
| 449 | } |
||
| 450 |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.