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 | * @var $data description |
||
26 | */ |
||
27 | //private $data; |
||
28 | |||
29 | |||
30 | |||
31 | /** |
||
32 | * Description. |
||
33 | * |
||
34 | * @param datatype $variable Description |
||
|
|||
35 | * |
||
36 | * @throws Exception |
||
37 | * |
||
38 | * @return void |
||
39 | */ |
||
40 | public function getIndex() |
||
41 | { |
||
42 | $title = "A index page"; |
||
43 | $view = $this->di->get("view"); |
||
44 | $pageRender = $this->di->get("pageRender"); |
||
45 | |||
46 | $data = [ |
||
47 | "content" => "An index page", |
||
48 | ]; |
||
49 | |||
50 | $view->add("default2/article", $data); |
||
51 | |||
52 | $pageRender->renderPage(["title" => $title]); |
||
53 | } |
||
54 | |||
55 | |||
56 | |||
57 | /** |
||
58 | * Description. |
||
59 | * |
||
60 | * @param datatype $variable Description |
||
61 | * |
||
62 | * @throws Exception |
||
63 | * |
||
64 | * @return void |
||
65 | */ |
||
66 | View Code Duplication | public function getLogin() |
|
81 | |||
82 | |||
83 | |||
84 | /** |
||
85 | * Description. |
||
86 | * |
||
87 | * @param datatype $variable Description |
||
88 | * |
||
89 | * @throws Exception |
||
90 | * |
||
91 | * @return void |
||
92 | */ |
||
93 | View Code Duplication | public function getCreateUser($message = null) |
|
108 | |||
109 | |||
110 | |||
111 | /** |
||
112 | * Description. |
||
113 | * |
||
114 | * @param datatype $variable Description |
||
115 | * |
||
116 | * @throws Exception |
||
117 | * |
||
118 | * @return void |
||
119 | */ |
||
120 | public function postCreatingUser() |
||
171 | |||
172 | |||
173 | |||
174 | /** |
||
175 | * Description. |
||
176 | * |
||
177 | * @param datatype $variable Description |
||
178 | * |
||
179 | * @throws Exception |
||
180 | * |
||
181 | * @return void |
||
182 | */ |
||
183 | public function getUserProfile() |
||
202 | |||
203 | |||
204 | |||
205 | /** |
||
206 | * Description. |
||
207 | * |
||
208 | * @param datatype $variable Description |
||
209 | * |
||
210 | * @throws Exception |
||
211 | * |
||
212 | * @return void |
||
213 | */ |
||
214 | public function validateUser() |
||
262 | |||
263 | |||
264 | |||
265 | /** |
||
266 | * Description. |
||
267 | * |
||
268 | * @param datatype $variable Description |
||
269 | * |
||
270 | * @throws Exception |
||
271 | * |
||
272 | * @return void |
||
273 | */ |
||
274 | View Code Duplication | public function updateGetUserProfile($message = null) |
|
293 | |||
294 | |||
295 | |||
296 | /** |
||
297 | * Description. |
||
298 | * |
||
299 | * @param datatype $variable Description |
||
300 | * |
||
301 | * @throws Exception |
||
302 | * |
||
303 | * @return void |
||
304 | */ |
||
305 | public function updatePostUserProfile() |
||
341 | |||
342 | |||
343 | |||
344 | /** |
||
345 | * Description. |
||
346 | * |
||
347 | * @param datatype $variable Description |
||
348 | * |
||
349 | * @throws Exception |
||
350 | * |
||
351 | * @return void |
||
352 | */ |
||
353 | public function getLogout() |
||
363 | |||
364 | |||
365 | |||
366 | /** |
||
367 | * Description. |
||
368 | * |
||
369 | * @param datatype $variable Description |
||
370 | * |
||
371 | * @throws Exception |
||
372 | * |
||
373 | * @return void |
||
374 | */ |
||
375 | public function getAdmin() |
||
392 | |||
393 | |||
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 getAdminUpdateUser($message = "", $userId = null) |
|
427 | |||
428 | |||
429 | |||
430 | |||
431 | /** |
||
432 | * Description. |
||
433 | * |
||
434 | * @param datatype $variable Description |
||
435 | * |
||
436 | * @throws Exception |
||
437 | * |
||
438 | * @return void |
||
439 | */ |
||
440 | public function postAdminUpdateUser() |
||
473 | |||
474 | |||
475 | |||
476 | /** |
||
477 | * Description. |
||
478 | * |
||
479 | * @param datatype $variable Description |
||
480 | * |
||
481 | * @throws Exception |
||
482 | * |
||
483 | * @return void |
||
484 | */ |
||
485 | View Code Duplication | public function getAdminCreateUser($message = null) |
|
499 | |||
500 | |||
501 | |||
502 | /** |
||
503 | * Description. |
||
504 | * |
||
505 | * @param datatype $variable Description |
||
506 | * |
||
507 | * @throws Exception |
||
508 | * |
||
509 | * @return void |
||
510 | */ |
||
511 | public function postAdminCreateUser() |
||
541 | |||
542 | |||
543 | |||
544 | |||
545 | /** |
||
546 | * Description. |
||
547 | * |
||
548 | * @param datatype $variable Description |
||
549 | * |
||
550 | * @throws Exception |
||
551 | * |
||
552 | * @return void |
||
553 | */ |
||
554 | public function getAdminDeleteUser() |
||
571 | } |
||
572 |
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.