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 |
||
| 31 | class CommentController extends RestController implements ClassResourceInterface |
||
| 32 | { |
||
| 33 | use RequestParametersTrait; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Returns list of field-descriptors. |
||
| 37 | * |
||
| 38 | * @Get("/comments/fields") |
||
| 39 | * |
||
| 40 | * @return Response |
||
| 41 | */ |
||
| 42 | public function getFieldsAction() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Returns list of comments. |
||
| 49 | * |
||
| 50 | * @param Request $request |
||
| 51 | * |
||
| 52 | * @return Response |
||
| 53 | */ |
||
| 54 | 3 | public function cgetAction(Request $request) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * Returns single comment. |
||
| 94 | * |
||
| 95 | * @param int $id |
||
| 96 | * |
||
| 97 | * @return Response |
||
| 98 | * |
||
| 99 | * @throws EntityNotFoundException |
||
| 100 | */ |
||
| 101 | 1 | public function getAction($id) |
|
| 110 | |||
| 111 | /** |
||
| 112 | * Update comment. |
||
| 113 | * |
||
| 114 | * @param int $id |
||
| 115 | * @param Request $request |
||
| 116 | * |
||
| 117 | * @return Response |
||
| 118 | * |
||
| 119 | * @throws EntityNotFoundException |
||
| 120 | */ |
||
| 121 | 1 | View Code Duplication | public function putAction($id, Request $request) |
| 136 | |||
| 137 | /** |
||
| 138 | * Delete comment identified by id. |
||
| 139 | * |
||
| 140 | * @param int $id |
||
| 141 | * |
||
| 142 | * @return Response |
||
| 143 | */ |
||
| 144 | 1 | View Code Duplication | public function deleteAction($id) |
| 151 | |||
| 152 | /** |
||
| 153 | * Delete multiple comments identified by ids parameter. |
||
| 154 | * |
||
| 155 | * @param Request $request |
||
| 156 | * |
||
| 157 | * @return Response |
||
| 158 | */ |
||
| 159 | 1 | View Code Duplication | public function cdeleteAction(Request $request) |
| 172 | |||
| 173 | /** |
||
| 174 | * trigger a action for given comment specified over action get-parameter |
||
| 175 | * - publish: Publish a comment |
||
| 176 | * - unpublish: Unpublish a comment. |
||
| 177 | * |
||
| 178 | * @Post("/comments/{id}") |
||
| 179 | * |
||
| 180 | * @param int $id |
||
| 181 | * @param Request $request |
||
| 182 | * |
||
| 183 | * @return Response |
||
| 184 | * |
||
| 185 | * @throws RestException |
||
| 186 | */ |
||
| 187 | 2 | public function postTriggerAction($id, Request $request) |
|
| 213 | |||
| 214 | /** |
||
| 215 | * Returns array of field-descriptors. |
||
| 216 | * |
||
| 217 | 3 | * @return FieldDescriptorInterface[] |
|
| 218 | */ |
||
| 219 | 3 | private function getFieldDescriptors() |
|
| 224 | } |
||
| 225 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: