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