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