| Conditions | 3 |
| Paths | 3 |
| Total Lines | 23 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 24 | 64 | public function validate($value, object $rule, ValidationContext $context): Result |
|
| 25 | { |
||
| 26 | 64 | if (!$rule instanceof HasLength) { |
|
| 27 | 1 | throw new UnexpectedRuleException(HasLength::class, $rule); |
|
| 28 | } |
||
| 29 | |||
| 30 | 63 | $result = new Result(); |
|
| 31 | |||
| 32 | 63 | if (!is_string($value)) { |
|
| 33 | 5 | $result->addError( |
|
| 34 | 5 | $rule->getMessage(), |
|
| 35 | [ |
||
| 36 | 5 | 'attribute' => $context->getAttribute(), |
|
| 37 | 'value' => $value, |
||
| 38 | ], |
||
| 39 | ); |
||
| 40 | 5 | return $result; |
|
| 41 | } |
||
| 42 | |||
| 43 | 58 | $length = mb_strlen($value, $rule->getEncoding()); |
|
| 44 | 58 | $this->validateLimits($value, $rule, $context, $length, $result); |
|
| 45 | |||
| 46 | 58 | return $result; |
|
| 47 | } |
||
| 49 |