Conditions | 8 |
Paths | 8 |
Total Lines | 78 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
108 | protected function getRequestResult() |
||
109 | { |
||
110 | $argumentsMissing = $this->initializeArguments(); |
||
111 | |||
112 | if (false === empty($argumentsMissing)) { |
||
113 | throw new InvalidArgumentValueException( |
||
114 | 'One or more arguments are missing in the request: "' . implode('", "', $argumentsMissing) . '".', |
||
115 | 1487673983 |
||
116 | ); |
||
117 | } |
||
118 | |||
119 | /** @var FormObjectFactory $formObjectFactory */ |
||
120 | $formObjectFactory = Core::instantiate(FormObjectFactory::class); |
||
121 | |||
122 | $formObject = $formObjectFactory->getInstanceFromClassName($this->formClassName, $this->formName); |
||
123 | $validationResult = $formObject->getConfigurationValidationResult(); |
||
124 | |||
125 | if (true === $validationResult->hasErrors()) { |
||
126 | throw new InvalidConfigurationException( |
||
127 | 'The form configuration contains errors.', |
||
128 | 1487671395 |
||
129 | ); |
||
130 | } |
||
131 | |||
132 | $formConfiguration = $formObject->getConfiguration(); |
||
133 | |||
134 | if (false === $formConfiguration->hasField($this->fieldName)) { |
||
135 | throw new EntryNotFoundException( |
||
136 | 'The field "' . $this->fieldName . '" was not found in the form "' . $this->formName . '" with class "' . $this->formClassName . '".', |
||
137 | 1487671603 |
||
138 | ); |
||
139 | } |
||
140 | |||
141 | $field = $formConfiguration->getField($this->fieldName); |
||
142 | |||
143 | if (false === $field->hasValidation($this->validatorName)) { |
||
144 | throw new EntryNotFoundException( |
||
145 | 'The field "' . $this->fieldName . '" does not have a rule "' . $this->validatorName . '".', |
||
146 | 1487672956 |
||
147 | ); |
||
148 | } |
||
149 | |||
150 | $fieldValidationConfiguration = $field->getValidationByName($this->validatorName); |
||
151 | |||
152 | if (false === $fieldValidationConfiguration->doesUseAjax()) { |
||
153 | throw new InvalidConfigurationException( |
||
154 | 'The validation "' . $this->validatorName . '" of the field "' . $this->fieldName . '" is not configured to work with Ajax. Please add the option "useAjax".', |
||
155 | 1487673434 |
||
156 | ); |
||
157 | } |
||
158 | |||
159 | $validatorClassName = $fieldValidationConfiguration->getClassName(); |
||
160 | |||
161 | if (false === in_array(ValidatorInterface::class, class_implements($validatorClassName))) { |
||
162 | throw new InvalidConfigurationException( |
||
163 | 'The class name "' . $validatorClassName . '" of the validation "' . $this->validatorName . '" of the field "' . $this->fieldName . '" must implement the interface "' . ValidatorInterface::class . '".', |
||
164 | 1487673690 |
||
165 | ); |
||
166 | } |
||
167 | |||
168 | $form = null; |
||
169 | |||
170 | if ('true' === $this->passObjectInstance) { |
||
171 | $form = $this->buildObject(); |
||
172 | $this->fieldValue = ObjectAccess::getProperty($form, $this->fieldName); |
||
173 | } |
||
174 | |||
175 | /** @var ValidatorInterface $validatorInstance */ |
||
176 | $validatorInstance = Core::instantiate( |
||
177 | $validatorClassName, |
||
178 | $fieldValidationConfiguration->getOptions(), |
||
179 | $form, |
||
180 | $this->fieldName, |
||
181 | $fieldValidationConfiguration->getMessages() |
||
182 | ); |
||
183 | |||
184 | return $this->convertResultToJson($validatorInstance->validate($this->fieldValue)); |
||
185 | } |
||
186 | |||
271 |
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: