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 |
||
18 | class CommentController implements ContainerInjectableInterface |
||
19 | { |
||
20 | use ContainerInjectableTrait; |
||
21 | |||
22 | |||
23 | /** |
||
24 | * @var $data description |
||
25 | */ |
||
26 | //private $data; |
||
27 | |||
28 | |||
29 | // /** |
||
30 | // * The initialize method is optional and will always be called before the |
||
31 | // * target method/action. This is a convienient method where you could |
||
32 | // * setup internal properties that are commonly used by several methods. |
||
33 | // * |
||
34 | // * @return void |
||
35 | // */ |
||
36 | // public function initialize() : void |
||
37 | // { |
||
38 | // ; |
||
39 | // } |
||
40 | |||
41 | |||
42 | /** |
||
43 | * Description. |
||
44 | * |
||
45 | * @param datatype $variable Description |
||
|
|||
46 | * |
||
47 | * @return object as a response object |
||
48 | * @throws Exception |
||
49 | * |
||
50 | */ |
||
51 | public function indexActionGet(): object |
||
52 | { |
||
53 | $user_id = $this->di->get("session")->get("user_id"); |
||
54 | var_dump($user_id); |
||
55 | if (!$user_id) { |
||
56 | $this->di->get("response")->redirect("user/login"); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | View Code Duplication | public function questionAction(int $questionId): object |
|
76 | |||
77 | |||
78 | View Code Duplication | public function answerAction(int $answerId): object |
|
94 | } |
||
95 |
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.