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