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