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 |
||
19 | class CommController implements |
||
20 | ConfigureInterface, |
||
21 | InjectionAwareInterface |
||
22 | { |
||
23 | use ConfigureTrait, |
||
24 | InjectionAwareTrait; |
||
25 | |||
26 | |||
27 | /** |
||
28 | * Sends data to view |
||
29 | * |
||
30 | * @param string $title |
||
31 | * @param string $crud, path to view |
||
|
|||
32 | * @param array $data, htmlcontent to view |
||
33 | */ |
||
34 | public function toRender($title, $crud, $data) |
||
42 | |||
43 | |||
44 | /** |
||
45 | * Show all items. |
||
46 | * |
||
47 | * @return void |
||
48 | */ |
||
49 | View Code Duplication | public function getIndex() |
|
62 | |||
63 | |||
64 | |||
65 | /** |
||
66 | * Handler with form to create a new item. |
||
67 | * |
||
68 | * @return void |
||
69 | */ |
||
70 | public function getPostCreateItem($id = null) |
||
93 | |||
94 | |||
95 | /** |
||
96 | * |
||
97 | * @return sessionobject |
||
98 | */ |
||
99 | public function getSess() |
||
105 | |||
106 | |||
107 | /** |
||
108 | * Handler with form to delete an item. |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | View Code Duplication | public function getPostDeleteItem($id) |
|
133 | |||
134 | |||
135 | |||
136 | /** |
||
137 | * Handler with form to update an item. |
||
138 | * |
||
139 | * @return void |
||
140 | */ |
||
141 | View Code Duplication | public function getPostAdminDeleteItem() |
|
155 | |||
156 | |||
157 | |||
158 | /** |
||
159 | * Handler with form to update an item. |
||
160 | * |
||
161 | * @return void |
||
162 | */ |
||
163 | View Code Duplication | public function getPostUpdateItem($id) |
|
185 | |||
186 | |||
187 | /** |
||
188 | * Handler with form to just show an item. |
||
189 | * |
||
190 | * @return void |
||
191 | */ |
||
192 | View Code Duplication | public function getPostShow($id) |
|
204 | } |
||
205 |
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.