| Total Complexity | 4 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | abstract class AbstractValidation implements Validation |
||
| 10 | { |
||
| 11 | use GuardForValidation, |
||
| 12 | MaybeBelongsToField; |
||
| 13 | |||
| 14 | protected string $message; |
||
| 15 | |||
| 16 | public function __construct(?string $message = null) |
||
| 17 | { |
||
| 18 | $this->message = $message ?? sprintf('Constraint violation: %s', get_class($this)); |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @inheritDoc |
||
| 23 | */ |
||
| 24 | public function validate(mixed $input, array $context = []): Result |
||
| 25 | { |
||
| 26 | $result = $this->newEmptyValidationResult(); |
||
| 27 | return $this->evaluate($input, $context) ? $result: $result->error($this->message); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param mixed $input |
||
| 32 | * @param array $context |
||
| 33 | * @return bool |
||
| 34 | */ |
||
| 35 | public function isValid(mixed $input, array $context = []): bool |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param mixed $input |
||
| 42 | * @param array $context |
||
| 43 | * @return bool |
||
| 44 | */ |
||
| 45 | abstract protected function evaluate(mixed $input, array $context = []): bool; |
||
| 46 | } |
||
| 47 |