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, |
||
| 21 | InjectionAwareTrait; |
||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | /** |
||
| 26 | * @var $data description |
||
| 27 | */ |
||
| 28 | //private $data; |
||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | /** |
||
| 33 | * Description. |
||
| 34 | * |
||
| 35 | * @param datatype $variable Description |
||
|
|
|||
| 36 | * |
||
| 37 | * @throws Exception |
||
| 38 | * |
||
| 39 | * @return void |
||
| 40 | */ |
||
| 41 | View Code Duplication | public function getIndex() |
|
| 51 | |||
| 52 | |||
| 53 | |||
| 54 | /** |
||
| 55 | * Description. |
||
| 56 | * |
||
| 57 | * @param datatype $variable Description |
||
| 58 | * |
||
| 59 | * @throws Exception |
||
| 60 | * |
||
| 61 | * @return void |
||
| 62 | */ |
||
| 63 | View Code Duplication | public function getPostLogin() |
|
| 80 | |||
| 81 | |||
| 82 | |||
| 83 | /** |
||
| 84 | * Description. |
||
| 85 | * |
||
| 86 | * @param datatype $variable Description |
||
| 87 | * |
||
| 88 | * @throws Exception |
||
| 89 | * |
||
| 90 | * @return void |
||
| 91 | */ |
||
| 92 | View Code Duplication | public function getPostCreateUser() |
|
| 109 | |||
| 110 | /** |
||
| 111 | * Handler with form to update a user. |
||
| 112 | * |
||
| 113 | * @return void |
||
| 114 | */ |
||
| 115 | View Code Duplication | public function getPostUpdateUser($id) |
|
| 133 | |||
| 134 | /** |
||
| 135 | * Description. |
||
| 136 | * |
||
| 137 | * @param datatype $variable Description |
||
| 138 | * |
||
| 139 | * @throws Exception |
||
| 140 | * |
||
| 141 | * @return void |
||
| 142 | */ |
||
| 143 | public function loginUser($input) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Description. |
||
| 150 | * |
||
| 151 | * @param datatype $variable Description |
||
| 152 | * |
||
| 153 | * @throws Exception |
||
| 154 | * |
||
| 155 | * @return void |
||
| 156 | */ |
||
| 157 | View Code Duplication | public function logoutUser() |
|
| 167 | |||
| 168 | /** |
||
| 169 | * Description. |
||
| 170 | * |
||
| 171 | * @param datatype $variable Description |
||
| 172 | * |
||
| 173 | * @throws Exception |
||
| 174 | * |
||
| 175 | * @return void |
||
| 176 | */ |
||
| 177 | View Code Duplication | public function getIDByUser($userInput) |
|
| 185 | |||
| 186 | /** |
||
| 187 | * Description. |
||
| 188 | * |
||
| 189 | * @param datatype $variable Description |
||
| 190 | * |
||
| 191 | * @throws Exception |
||
| 192 | * |
||
| 193 | * @return void |
||
| 194 | */ |
||
| 195 | public function adminControl() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Delete user |
||
| 212 | * |
||
| 213 | * @return void |
||
| 214 | */ |
||
| 215 | public function removeUser($id) |
||
| 221 | } |
||
| 222 |
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.