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 | View Code Duplication | public function getPostCreateItem($id = null) |
|
| 93 | |||
| 94 | |||
| 95 | /** |
||
| 96 | * Handler with form to delete an item. |
||
| 97 | * |
||
| 98 | * @return void |
||
| 99 | */ |
||
| 100 | View Code Duplication | public function getPostDeleteItem($id) |
|
| 123 | |||
| 124 | |||
| 125 | |||
| 126 | /** |
||
| 127 | * Handler with form to update an item. |
||
| 128 | * |
||
| 129 | * @return void |
||
| 130 | */ |
||
| 131 | View Code Duplication | public function getPostAdminDeleteItem() |
|
| 145 | |||
| 146 | |||
| 147 | |||
| 148 | /** |
||
| 149 | * Handler with form to update an item. |
||
| 150 | * |
||
| 151 | * @return void |
||
| 152 | */ |
||
| 153 | View Code Duplication | public function getPostUpdateItem($id) |
|
| 176 | |||
| 177 | |||
| 178 | /** |
||
| 179 | * Handler with form to just show an item. |
||
| 180 | * |
||
| 181 | * @return void |
||
| 182 | */ |
||
| 183 | View Code Duplication | public function getPostShow($id) |
|
| 195 | } |
||
| 196 |
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.