| Conditions | 3 |
| Paths | 3 |
| Total Lines | 20 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public function validate($value, object $rule, ValidationContext $context): Result |
||
| 25 | { |
||
| 26 | if (!$rule instanceof Length) { |
||
| 27 | throw new UnexpectedRuleException(Length::class, $rule); |
||
| 28 | } |
||
| 29 | |||
| 30 | $result = new Result(); |
||
| 31 | if (!is_string($value)) { |
||
| 32 | $result->addError($rule->getIncorrectInputMessage(), [ |
||
| 33 | 'attribute' => $context->getTranslatedAttribute(), |
||
| 34 | 'type' => get_debug_type($value), |
||
| 35 | ]); |
||
| 36 | |||
| 37 | return $result; |
||
| 38 | } |
||
| 39 | |||
| 40 | $length = mb_strlen($value, $rule->getEncoding()); |
||
| 41 | $this->validateLimits($rule, $context, $length, $result); |
||
| 42 | |||
| 43 | return $result; |
||
| 44 | } |
||
| 46 |