| Total Complexity | 3 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 12 | class Regex implements ValidatorInterface |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Checks if $value is a valid value for this datatype considering the validators. |
||
| 16 | * |
||
| 17 | * @param mixed $value |
||
| 18 | * @param array $options The options passed to the validator |
||
| 19 | * @param Datatype $datatype The datatype being validator. |
||
| 20 | * @param Model $model The entire model, if you your field depends on other things of the model. may be null. |
||
| 21 | * @throws ValidatorException If invalid, with the message. |
||
| 22 | * @return mixed |
||
| 23 | */ |
||
| 24 | public static function validate($value, array $options = [], Datatype $datatype, ?Model $model = null) |
||
| 25 | { |
||
| 26 | if (preg_match($options['value'], $value)) { |
||
| 27 | return $value; |
||
| 28 | } |
||
| 29 | throw new ValidatorException('Value does not match expected regular expression'); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Documents this validator. |
||
| 34 | * |
||
| 35 | * @return ValidatorMetadata |
||
| 36 | */ |
||
| 37 | public static function getMetadata(): ValidatorMetadata |
||
| 47 | ) |
||
| 48 | ] |
||
| 52 |