| Conditions | 12 |
| Paths | 26 |
| Total Lines | 48 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 41 | public function validate(mixed $value, object $rule, ?ValidationContext $context = null): Result |
||
| 42 | { |
||
| 43 | if (!$rule instanceof Nested) { |
||
| 44 | throw new UnexpectedRuleException(Nested::class, $rule); |
||
| 45 | } |
||
| 46 | |||
| 47 | $compoundResult = new Result(); |
||
| 48 | if (!is_object($value) && !is_array($value)) { |
||
| 49 | $message = sprintf('Value should be an array or an object. %s given.', gettype($value)); |
||
| 50 | $compoundResult->addError($message); |
||
| 51 | |||
| 52 | return $compoundResult; |
||
| 53 | } |
||
| 54 | |||
| 55 | $value = (array)$value; |
||
| 56 | |||
| 57 | $results = []; |
||
| 58 | foreach ($rule->rules as $valuePath => $rules) { |
||
| 59 | $result = new Result((string)$valuePath); |
||
| 60 | |||
| 61 | if ($rule->errorWhenPropertyPathIsNotFound && !ArrayHelper::pathExists($value, $valuePath)) { |
||
| 62 | $compoundResult->addError($rule->propertyPathIsNotFoundMessage, ['path' => $valuePath], $valuePath); |
||
| 63 | |||
| 64 | continue; |
||
| 65 | } |
||
| 66 | |||
| 67 | $rules = is_array($rules) ? $rules : [$rules]; |
||
| 68 | $validatedValue = ArrayHelper::getValueByPath($value, $valuePath); |
||
| 69 | |||
| 70 | $itemResult = $context->getValidator()->validate($validatedValue, $rules); |
||
|
|
|||
| 71 | |||
| 72 | if ($itemResult->isValid()) { |
||
| 73 | continue; |
||
| 74 | } |
||
| 75 | |||
| 76 | foreach ($itemResult->getErrors() as $error) { |
||
| 77 | $result->mergeError($error); |
||
| 78 | } |
||
| 79 | $results[] = $result; |
||
| 80 | } |
||
| 81 | |||
| 82 | foreach ($results as $result) { |
||
| 83 | foreach ($result->getErrors() as $error) { |
||
| 84 | $compoundResult->mergeError($error); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | return $compoundResult; |
||
| 89 | } |
||
| 91 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.