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() |
||
| 43 | // { |
||
| 44 | // $title = "A index page"; |
||
| 45 | // $view = $this->di->get("view"); |
||
| 46 | // $pageRender = $this->di->get("pageRender"); |
||
| 47 | // |
||
| 48 | // $data = [ |
||
| 49 | // "content" => "An index page", |
||
| 50 | // ]; |
||
| 51 | // |
||
| 52 | // $view->add("default2/article", $data); |
||
| 53 | // |
||
| 54 | // $pageRender->renderPage(["title" => $title]); |
||
| 55 | // } |
||
| 56 | |||
| 57 | |||
| 58 | |||
| 59 | /** |
||
| 60 | * Description. |
||
| 61 | * |
||
| 62 | * @param datatype $variable Description |
||
|
|
|||
| 63 | * |
||
| 64 | * @throws Exception |
||
| 65 | * |
||
| 66 | * @return void |
||
| 67 | */ |
||
| 68 | View Code Duplication | public function getPostLogin() |
|
| 86 | |||
| 87 | |||
| 88 | |||
| 89 | /** |
||
| 90 | * Description. |
||
| 91 | * |
||
| 92 | * @param datatype $variable Description |
||
| 93 | * |
||
| 94 | * @throws Exception |
||
| 95 | * |
||
| 96 | * @return void |
||
| 97 | */ |
||
| 98 | View Code Duplication | public function getPostCreateUser() |
|
| 115 | |||
| 116 | /** |
||
| 117 | * Description. |
||
| 118 | * |
||
| 119 | * @param datatype $variable Description |
||
| 120 | * |
||
| 121 | * @throws Exception |
||
| 122 | * |
||
| 123 | * @return void |
||
| 124 | */ |
||
| 125 | public function editAllUsers() |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Description. |
||
| 152 | * |
||
| 153 | * @param datatype $variable Description |
||
| 154 | * |
||
| 155 | * @throws Exception |
||
| 156 | * |
||
| 157 | * @return void |
||
| 158 | */ |
||
| 159 | public function showProfile() |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Description. |
||
| 184 | * |
||
| 185 | * @param datatype $variable Description |
||
| 186 | * |
||
| 187 | * @throws Exception |
||
| 188 | * |
||
| 189 | * @return void |
||
| 190 | */ |
||
| 191 | public function editUser($id) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Description. |
||
| 225 | * |
||
| 226 | * @param datatype $variable Description |
||
| 227 | * |
||
| 228 | * @throws Exception |
||
| 229 | * |
||
| 230 | * @return void |
||
| 231 | */ |
||
| 232 | public function editOneUser($id) |
||
| 261 | } |
||
| 262 |
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.