Conditions | 4 |
Paths | 4 |
Total Lines | 17 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 4.128 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
15 | 9 | public function validate(mixed $value, object $rule, ValidatorInterface $validator, ?ValidationContext $context = null): Result |
|
16 | { |
||
17 | 9 | $result = new Result(); |
|
18 | |||
19 | 9 | if (!is_iterable($value)) { |
|
20 | $result->addError($rule->iterableMessage); |
||
21 | return $result; |
||
22 | } |
||
23 | |||
24 | 9 | if (!ArrayHelper::isSubset($value, $rule->values, $rule->strict)) { |
|
25 | 3 | $values = is_array($rule->values) ? $rule->values : iterator_to_array($rule->values); |
|
26 | 3 | $valuesString = '"' . implode('", "', $values) . '"'; |
|
27 | |||
28 | 3 | $result->addError($rule->subsetMessage, ['values' => $valuesString]); |
|
29 | } |
||
30 | |||
31 | 9 | return $result; |
|
32 | } |
||
34 |