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