Conditions | 7 |
Paths | 6 |
Total Lines | 36 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 7.2694 |
Changes | 0 |
1 | <?php |
||
18 | 4 | public function validate(mixed $value, object $rule, ?ValidationContext $context = null): Result |
|
19 | { |
||
20 | 4 | if (!$rule instanceof Each) { |
|
21 | 1 | throw new UnexpectedRuleException(Each::class, $rule); |
|
22 | } |
||
23 | |||
24 | /** |
||
25 | * @var iterable<RuleInterface> $rules |
||
26 | */ |
||
27 | 3 | $rules = $rule->rules; |
|
28 | 3 | if ($rules === []) { |
|
29 | throw new InvalidArgumentException('Rules are required.'); |
||
30 | } |
||
31 | |||
32 | 3 | $result = new Result(); |
|
33 | 3 | if (!is_iterable($value)) { |
|
34 | $result->addError($rule->incorrectInputMessage); |
||
35 | |||
36 | return $result; |
||
37 | } |
||
38 | |||
39 | 3 | foreach ($value as $index => $item) { |
|
40 | /** |
||
41 | * @psalm-suppress InvalidArgument |
||
42 | */ |
||
43 | 3 | $itemResult = $context->getValidator()->validate($item, [$index => $rules]); |
|
|
|||
44 | 3 | if ($itemResult->isValid()) { |
|
45 | 3 | continue; |
|
46 | } |
||
47 | |||
48 | 2 | foreach ($itemResult->getErrors() as $error) { |
|
49 | 2 | $result->mergeError($error); |
|
50 | } |
||
51 | } |
||
52 | |||
53 | 3 | return $result; |
|
54 | } |
||
56 |
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.