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 |
||
14 | class ManagersController extends FOSRestController |
||
15 | { |
||
16 | use Traits\TokenFromHeaderTrait; |
||
17 | use Traits\HandleUserTrait; |
||
18 | |||
19 | /** |
||
20 | * NOTE: use annotation for routing here even |
||
21 | * if the FOSRestBundle is automatically able |
||
22 | * to handle them. In fact, ParamConverter is |
||
23 | * not supported by FOSRestController. |
||
24 | * |
||
25 | * @Annotations\Post("/users") |
||
26 | * @ParamConverter("user", converter="fos_rest.request_body") |
||
27 | */ |
||
28 | public function postUserAction(User $user) |
||
75 | |||
76 | /** |
||
77 | * @Annotations\Put("/users/{id}") |
||
78 | * |
||
79 | * @ParamConverter("updatedUser", converter="fos_rest.request_body") |
||
80 | * |
||
81 | * @param User $user |
||
82 | * @param User $updatedUser |
||
83 | */ |
||
84 | public function putUserAction( |
||
116 | |||
117 | /** |
||
118 | * @param User $user |
||
119 | * @param Request $request |
||
120 | */ |
||
121 | public function putUserRolesAction( |
||
133 | |||
134 | /** |
||
135 | * @param User $user |
||
136 | */ |
||
137 | public function getUserAction(User $user) |
||
143 | |||
144 | /** |
||
145 | * Disable one given user. |
||
146 | * |
||
147 | * @param User $user |
||
148 | */ |
||
149 | public function patchUserDisableAction(User $user) |
||
157 | |||
158 | /** |
||
159 | * @param User $user |
||
160 | */ |
||
161 | public function patchUserEnableAction(User $user) |
||
169 | |||
170 | /** |
||
171 | * @param User $user |
||
172 | * @param Request $request |
||
173 | * |
||
174 | * @Annotations\put("/users/{id}/password") |
||
175 | * |
||
176 | * @return Response |
||
177 | */ |
||
178 | 2 | public function putUsersPasswordAction(User $user, Request $request) |
|
207 | |||
208 | /** |
||
209 | * Check if the JSON sent data is correct |
||
210 | * for the current called action |
||
211 | * and throws a bad request exception if the input is wrong. |
||
212 | * |
||
213 | * @param Request $request |
||
214 | * @param array $keys |
||
215 | * @param string $message |
||
216 | * |
||
217 | * @return array |
||
218 | * |
||
219 | * @throws BadRequestHttpException |
||
220 | */ |
||
221 | 1 | View Code Duplication | private function requestIsJsonWithKeysOrThrow( |
236 | |||
237 | 2 | private function isCurrentUserAdmin() |
|
244 | } |
||
245 |
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: