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 |
||
| 28 | class ThreadController extends RestController implements ClassResourceInterface |
||
| 29 | { |
||
| 30 | use RequestParametersTrait; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Returns list of field-descriptors. |
||
| 34 | * |
||
| 35 | * @Get("/threads/fields") |
||
| 36 | * |
||
| 37 | * @return Response |
||
| 38 | */ |
||
| 39 | public function getFieldsAction() |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Returns list of threads. |
||
| 46 | * |
||
| 47 | * @param Request $request |
||
| 48 | * |
||
| 49 | * @return Response |
||
| 50 | */ |
||
| 51 | 3 | public function cgetAction(Request $request) |
|
| 84 | |||
| 85 | /** |
||
| 86 | * Returns single thread. |
||
| 87 | * |
||
| 88 | * @param int $id |
||
| 89 | * |
||
| 90 | * @return Response |
||
| 91 | * |
||
| 92 | * @throws EntityNotFoundException |
||
| 93 | */ |
||
| 94 | 1 | public function getAction($id) |
|
| 103 | |||
| 104 | /** |
||
| 105 | * Update thread. |
||
| 106 | * |
||
| 107 | * @param int $id |
||
| 108 | * @param Request $request |
||
| 109 | * |
||
| 110 | * @return Response |
||
| 111 | * |
||
| 112 | * @throws EntityNotFoundException |
||
| 113 | */ |
||
| 114 | 1 | View Code Duplication | public function putAction($id, Request $request) |
| 129 | |||
| 130 | /** |
||
| 131 | * Delete thread identified by id. |
||
| 132 | * |
||
| 133 | * @param int $id |
||
| 134 | * |
||
| 135 | * @return Response |
||
| 136 | */ |
||
| 137 | 1 | View Code Duplication | public function deleteAction($id) |
| 144 | |||
| 145 | /** |
||
| 146 | * Delete multiple threads identified by ids parameter. |
||
| 147 | * |
||
| 148 | * @param Request $request |
||
| 149 | * |
||
| 150 | * @return Response |
||
| 151 | */ |
||
| 152 | 1 | View Code Duplication | public function cdeleteAction(Request $request) |
| 165 | |||
| 166 | /** |
||
| 167 | * Returns array of field-descriptors. |
||
| 168 | * |
||
| 169 | * @return FieldDescriptorInterface[] |
||
| 170 | */ |
||
| 171 | 3 | private function getFieldDescriptors() |
|
| 176 | } |
||
| 177 |
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: