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 |
||
| 16 | class UserController implements |
||
| 17 | ConfigureInterface, |
||
| 18 | InjectionAwareInterface |
||
| 19 | { |
||
| 20 | use ConfigureTrait, InjectionAwareTrait; |
||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | /** |
||
| 25 | * @var $data description |
||
| 26 | */ |
||
| 27 | //private $data; |
||
| 28 | |||
| 29 | |||
| 30 | |||
| 31 | /** |
||
| 32 | * Get details on item to load form with. |
||
| 33 | * |
||
| 34 | * @param integer $id get details on item with id. |
||
|
|
|||
| 35 | * |
||
| 36 | * @return object true if okey, false if something went wrong. |
||
| 37 | */ |
||
| 38 | 2 | public function getUserDetails($name) |
|
| 46 | |||
| 47 | /** |
||
| 48 | * Logout user by setting "user" == null in session. |
||
| 49 | * |
||
| 50 | * |
||
| 51 | * @return void |
||
| 52 | */ |
||
| 53 | public function logout() |
||
| 58 | |||
| 59 | |||
| 60 | /** |
||
| 61 | * Render page for users |
||
| 62 | * |
||
| 63 | * @return void |
||
| 64 | */ |
||
| 65 | 2 | public function renderPage($views, $title) |
|
| 72 | |||
| 73 | |||
| 74 | /** |
||
| 75 | * check if user is logged in |
||
| 76 | * |
||
| 77 | * @return void |
||
| 78 | */ |
||
| 79 | 2 | public function checkIsLogin() |
|
| 88 | |||
| 89 | |||
| 90 | |||
| 91 | |||
| 92 | /** |
||
| 93 | * Description. |
||
| 94 | * |
||
| 95 | * @param datatype $variable Description |
||
| 96 | * |
||
| 97 | * @throws Exception |
||
| 98 | * |
||
| 99 | * @return void |
||
| 100 | */ |
||
| 101 | 1 | View Code Duplication | public function getPostLogin() |
| 112 | |||
| 113 | |||
| 114 | |||
| 115 | /** |
||
| 116 | * Description. |
||
| 117 | * |
||
| 118 | * @param datatype $variable Description |
||
| 119 | * |
||
| 120 | * @throws Exception |
||
| 121 | * |
||
| 122 | * @return void |
||
| 123 | */ |
||
| 124 | 1 | View Code Duplication | public function getPostCreateUser() |
| 135 | |||
| 136 | /** |
||
| 137 | * Description. |
||
| 138 | * |
||
| 139 | * @param datatype $variable Description |
||
| 140 | * |
||
| 141 | * @throws Exception |
||
| 142 | * |
||
| 143 | * @return void |
||
| 144 | */ |
||
| 145 | 1 | public function getPostEditUser() |
|
| 159 | |||
| 160 | |||
| 161 | /** |
||
| 162 | * Render profile page |
||
| 163 | * |
||
| 164 | * @return void |
||
| 165 | */ |
||
| 166 | 1 | public function renderProfile() |
|
| 187 | } |
||
| 188 |
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.