Conditions | 7 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 7 |
Changes | 0 |
1 | <?php |
||
20 | 14 | public function validate(mixed $value, object $rule, ?ValidationContext $context = null): Result |
|
21 | { |
||
22 | 14 | if (!$rule instanceof Regex) { |
|
23 | 1 | throw new UnexpectedRuleException(Regex::class, $rule); |
|
24 | } |
||
25 | |||
26 | 13 | $result = new Result(); |
|
27 | |||
28 | 13 | if (!is_string($value)) { |
|
29 | 7 | $result->addError($rule->incorrectInputMessage); |
|
30 | |||
31 | 7 | return $result; |
|
32 | } |
||
33 | |||
34 | if ( |
||
35 | 6 | (!$rule->not && !preg_match($rule->pattern, $value)) || |
|
36 | 6 | ($rule->not && preg_match($rule->pattern, $value)) |
|
37 | ) { |
||
38 | 3 | $result->addError($rule->message); |
|
39 | } |
||
40 | |||
41 | 6 | return $result; |
|
42 | } |
||
44 |