| Conditions | 4 |
| Paths | 4 |
| Total Lines | 20 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | 17 | public function validate(mixed $value, object $rule, ValidationContext $context): Result |
|
| 19 | 1 | { |
|
| 20 | if (!$rule instanceof Subset) { |
||
| 21 | throw new UnexpectedRuleException(Subset::class, $rule); |
||
| 22 | 16 | } |
|
| 23 | 16 | ||
| 24 | 4 | if (!is_iterable($value)) { |
|
| 25 | 4 | return (new Result())->addError($rule->getIncorrectInputMessage(), [ |
|
| 26 | 4 | 'attribute' => $context->getTranslatedAttribute(), |
|
| 27 | 'type' => get_debug_type($value), |
||
| 28 | ]); |
||
| 29 | } |
||
| 30 | 12 | ||
| 31 | 6 | if (!ArrayHelper::isSubset($value, $rule->getValues(), $rule->isStrict())) { |
|
| 32 | 6 | return (new Result())->addError($rule->getMessage(), [ |
|
| 33 | 1 | 'attribute' => $context->getTranslatedAttribute(), |
|
| 34 | ]); |
||
| 35 | } |
||
| 36 | 6 | ||
| 37 | return new Result(); |
||
| 38 | 6 | } |
|
| 40 |