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