| Conditions | 5 |
| Paths | 4 |
| Total Lines | 21 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 5.0144 |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | 31 | public function validate(mixed $value, object $rule, ?ValidationContext $context = null): Result |
|
| 30 | { |
||
| 31 | 31 | if (!$rule instanceof InRange) { |
|
| 32 | 1 | throw new UnexpectedRuleException(InRange::class, $rule); |
|
| 33 | } |
||
| 34 | |||
| 35 | 30 | $result = new Result(); |
|
| 36 | |||
| 37 | 30 | if ($value === null && $rule->isSkipOnEmpty()) { |
|
| 38 | return $result; |
||
| 39 | } |
||
| 40 | |||
| 41 | 30 | if ($rule->isNot() === ArrayHelper::isIn($value, $rule->getRange(), $rule->isStrict())) { |
|
| 42 | 18 | $formattedMessage = $this->formatter->format( |
|
| 43 | 18 | $rule->getMessage(), |
|
| 44 | 18 | ['attribute' => $context?->getAttribute(), 'value' => $value] |
|
| 45 | ); |
||
| 46 | 18 | $result->addError($formattedMessage); |
|
| 47 | } |
||
| 48 | |||
| 49 | 30 | return $result; |
|
| 50 | } |
||
| 52 |