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