Conditions | 6 |
Paths | 5 |
Total Lines | 25 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 6.3541 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | 3 | public function validate(mixed $value, object $rule, ValidatorInterface $validator, ?ValidationContext $context = null): Result |
|
19 | { |
||
20 | 3 | if ($rule->rules === null) { |
|
21 | throw new InvalidArgumentException('Rules are required.'); |
||
22 | } |
||
23 | |||
24 | 3 | $result = new Result(); |
|
25 | 3 | if (!is_iterable($value)) { |
|
26 | $result->addError($rule->incorrectInputMessage); |
||
27 | |||
28 | return $result; |
||
29 | } |
||
30 | |||
31 | 3 | foreach ($value as $index => $item) { |
|
32 | 3 | $itemResult = $validator->validate($item, [$index => $rule->rules]); |
|
33 | 3 | if ($itemResult->isValid()) { |
|
34 | 3 | continue; |
|
35 | } |
||
36 | |||
37 | 2 | foreach ($itemResult->getErrors() as $error) { |
|
38 | 2 | $result->merge($error); |
|
39 | } |
||
40 | } |
||
41 | |||
42 | 3 | return $result; |
|
43 | } |
||
45 |