| 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 | 32 | public function validate(mixed $value, object $rule, ?ValidationContext $context = null): Result |
|
| 30 | { |
||
| 31 | 32 | if (!$rule instanceof InRange) { |
|
| 32 | 1 | throw new UnexpectedRuleException(InRange::class, $rule); |
|
| 33 | } |
||
| 34 | |||
| 35 | 31 | $result = new Result(); |
|
| 36 | |||
| 37 | 31 | if ($value === null && $rule->shouldSkipOnEmpty()) { |
|
| 38 | return $result; |
||
| 39 | } |
||
| 40 | |||
| 41 | 31 | if ($rule->isNot() === ArrayHelper::isIn($value, $rule->getRange(), $rule->isStrict())) { |
|
| 42 | 19 | $formattedMessage = $this->formatter->format( |
|
| 43 | 19 | $rule->getMessage(), |
|
| 44 | 19 | ['attribute' => $context?->getAttribute(), 'value' => $value] |
|
| 45 | ); |
||
| 46 | 19 | $result->addError($formattedMessage); |
|
| 47 | } |
||
| 48 | |||
| 49 | 31 | return $result; |
|
| 50 | } |
||
| 52 |