| Total Complexity | 8 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 10 | final class OperatorValidator extends ConstraintValidator |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * {@inheritdoc} |
||
| 14 | */ |
||
| 15 | public function validate($input, Constraint $constraint): void |
||
| 16 | { |
||
| 17 | if (!$constraint instanceof Operator) { |
||
| 18 | throw new Exception\UnexpectedTypeException($constraint, Operator::class); // @codeCoverageIgnore |
||
| 19 | } |
||
| 20 | |||
| 21 | if (!$input instanceof InputInterface) { |
||
| 22 | throw new Exception\UnexpectedTypeException($input, InputInterface::class); // @codeCoverageIgnore |
||
| 23 | } |
||
| 24 | |||
| 25 | foreach ($this->getOperators($input) as $fieldName => $operator) { |
||
| 26 | if (false === \in_array($operator, $constraint->operators, true)) { |
||
| 27 | $this->context |
||
| 28 | ->buildViolation($constraint->message) |
||
| 29 | ->atPath($fieldName) |
||
| 30 | ->setParameter('{{ operator }}', $operator) |
||
| 31 | ->addViolation(); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param InputInterface $input |
||
| 38 | * |
||
| 39 | * @return \Generator|string[] |
||
| 40 | */ |
||
| 41 | private function getOperators(InputInterface $input): \Generator |
||
| 46 | } |
||
| 47 | } |
||
| 50 |