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 |
||
| 26 | class Form |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var FormFactory |
||
| 30 | */ |
||
| 31 | private $formFactory; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var DocumentType |
||
| 35 | */ |
||
| 36 | private $formType; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var ValidatorInterface |
||
| 40 | */ |
||
| 41 | private $validator; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param FormFactory $formFactory Factory, providing different file document instances. |
||
| 45 | * @param DocumentType $formType Type of form to be set |
||
| 46 | * @param ValidatorInterface $validator Validator to verify correctness of the provided data |
||
| 47 | */ |
||
| 48 | public function __construct( |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param Request $request request |
||
| 60 | * @param DocumentModel $model model |
||
| 61 | * |
||
| 62 | * @return \Symfony\Component\Form\Form |
||
| 63 | */ |
||
| 64 | public function getForm(Request $request, DocumentModel $model) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Validates the provided information against a form. |
||
| 72 | * |
||
| 73 | * @param FormInterface $form form to check |
||
| 74 | * @param DocumentModel $model Model to determine entity to be used |
||
| 75 | * @param FormDataMapperInterface $formDataMapper Mapps the entity to form fields |
||
| 76 | * @param string $jsonContent json data |
||
| 77 | * |
||
| 78 | * @throws ValidationException |
||
| 79 | * @return mixed |
||
| 80 | */ |
||
| 81 | public function checkForm( |
||
| 101 | |||
| 102 | /** |
||
| 103 | * validate raw json input |
||
| 104 | * |
||
| 105 | * @param Request $request request |
||
| 106 | * @param Response $response response |
||
| 107 | * @param string $content Alternative request content. |
||
| 108 | * |
||
| 109 | * @return void |
||
| 110 | */ |
||
| 111 | public function checkJsonRequest(Request $request, Response $response, $content = '') |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Validate JSON patch for any object |
||
| 161 | * |
||
| 162 | * @param array $jsonPatch json patch as array |
||
| 163 | * |
||
| 164 | * @throws InvalidJsonPatchException |
||
| 165 | * @return void |
||
| 166 | */ |
||
| 167 | public function checkJsonPatchRequest(array $jsonPatch) |
||
| 178 | /** |
||
| 179 | * Used for backwards compatibility to PHP 5.4 |
||
| 180 | * |
||
| 181 | * @return string |
||
| 182 | */ |
||
| 183 | private function getLastJsonErrorMessage() |
||
| 193 | } |
||
| 194 |
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: