| Conditions | 5 |
| Paths | 6 |
| Total Lines | 24 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 5 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 20 | 45 | public function validate(mixed $value, object $rule, ValidationContext $context): Result |
|
| 21 | { |
||
| 22 | 45 | if (!$rule instanceof Required) { |
|
| 23 | 1 | throw new UnexpectedRuleException(Required::class, $rule); |
|
| 24 | } |
||
| 25 | |||
| 26 | 44 | $result = new Result(); |
|
| 27 | 44 | if ($context->isAttributeMissing()) { |
|
| 28 | 5 | $result->addError($rule->getNotPassedMessage()); |
|
| 29 | |||
| 30 | 5 | return $result; |
|
| 31 | } |
||
| 32 | |||
| 33 | 40 | if (is_string($value)) { |
|
| 34 | 19 | $value = trim($value); |
|
| 35 | } |
||
| 36 | |||
| 37 | 40 | if (!(new SkipOnEmpty())($value, $context->isAttributeMissing())) { |
|
| 38 | 25 | return $result; |
|
| 39 | } |
||
| 40 | |||
| 41 | 15 | $result->addError($rule->getMessage()); |
|
| 42 | |||
| 43 | 15 | return $result; |
|
| 44 | } |
||
| 46 |