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 |
||
| 16 | class CommentController implements |
||
| 17 | ConfigureInterface, |
||
| 18 | InjectionAwareInterface |
||
| 19 | { |
||
| 20 | use ConfigureTrait, |
||
| 21 | InjectionAwareTrait; |
||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | /** |
||
| 26 | * @var $data description |
||
| 27 | */ |
||
| 28 | //private $data; |
||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | /** |
||
| 33 | * Description. |
||
| 34 | * |
||
| 35 | * @param datatype $variable Description |
||
|
|
|||
| 36 | * |
||
| 37 | * @throws Exception |
||
| 38 | * |
||
| 39 | * @return void |
||
| 40 | */ |
||
| 41 | 1 | public function getComments($test = "not_test") |
|
| 72 | |||
| 73 | /** |
||
| 74 | * Description. |
||
| 75 | * |
||
| 76 | * @param datatype $variable Description |
||
| 77 | * |
||
| 78 | * @throws Exception |
||
| 79 | * |
||
| 80 | * @return void |
||
| 81 | */ |
||
| 82 | View Code Duplication | public function getPostCreateComment() |
|
| 99 | |||
| 100 | /** |
||
| 101 | * Description. |
||
| 102 | * |
||
| 103 | * @param datatype $variable Description |
||
| 104 | * |
||
| 105 | * @throws Exception |
||
| 106 | * |
||
| 107 | * @return void |
||
| 108 | */ |
||
| 109 | public function getPostEditComment($key, $itemId) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Description. |
||
| 142 | * |
||
| 143 | * @param datatype $variable Description |
||
| 144 | * |
||
| 145 | * @throws Exception |
||
| 146 | * |
||
| 147 | * @return void |
||
| 148 | */ |
||
| 149 | View Code Duplication | public function deleteComment() |
|
| 166 | |||
| 167 | /** |
||
| 168 | * get a user's role |
||
| 169 | * @param string user's acronym |
||
| 170 | * |
||
| 171 | * @return integer user's role |
||
| 172 | **/ |
||
| 173 | 2 | public function getRole($acronym) |
|
| 181 | |||
| 182 | /** |
||
| 183 | * check if logged in user can edit the comment |
||
| 184 | * @param string commentid |
||
| 185 | * |
||
| 186 | * @return bool |
||
| 187 | **/ |
||
| 188 | public function isEditable($commentId, $user) |
||
| 201 | } |
||
| 202 |
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.