| Total Complexity | 5 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Coverage | 94.44% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 16 | class SameAs implements ValidatorInterface |
||
| 17 | { |
||
| 18 | 3 | public static function validate($value, array $options = [], ?Model $model = null) |
|
| 19 | { |
||
| 20 | 3 | if (!$model) { |
|
| 21 | 1 | throw new ValidatorException('Same as requires a model.'); |
|
| 22 | } |
||
| 23 | 2 | $modelData = $model->getData(); |
|
| 24 | |||
| 25 | 2 | $same = $options['target']; |
|
| 26 | 2 | if (!array_key_exists($same, $modelData)) { |
|
| 27 | throw new ValidatorException('Same as field not found.'); |
||
| 28 | } |
||
| 29 | 2 | if ($modelData[$same] !== $value) { |
|
| 30 | 1 | throw new ValidatorException('Field does not match ' . $same); |
|
| 31 | } |
||
| 32 | 1 | return $value; |
|
| 33 | } |
||
| 34 | |||
| 35 | 2 | public static function getMetadata(): Metadata |
|
| 45 | ) |
||
| 46 | ] |
||
| 50 |