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