| Conditions | 4 |
| Paths | 4 |
| Total Lines | 15 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 4.016 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 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 | } |
||
| 50 |