| Conditions | 5 |
| Paths | 5 |
| Total Lines | 24 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 5.246 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | 10 | public function validate(mixed $value, object $rule, ValidationContext $context): 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->getIterableMessage()); |
||
| 26 | |||
| 27 | return $result; |
||
| 28 | } |
||
| 29 | |||
| 30 | 9 | if (!ArrayHelper::isSubset($value, $rule->getValues(), $rule->isStrict())) { |
|
| 31 | 3 | $values = $rule->getValues() instanceof Traversable |
|
| 32 | ? iterator_to_array($rule->getValues()) |
||
| 33 | 3 | : $rule->getValues(); |
|
| 34 | 3 | $valuesString = '"' . implode('", "', $values) . '"'; |
|
|
|
|||
| 35 | |||
| 36 | 3 | $result->addError($rule->getSubsetMessage(), ['values' => $valuesString]); |
|
| 37 | } |
||
| 38 | |||
| 39 | 9 | return $result; |
|
| 40 | } |
||
| 42 |