| Conditions | 4 |
| Paths | 4 |
| Total Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 34 | public function validate($value, Constraint $constraint): void |
||
| 35 | { |
||
| 36 | if (!$constraint instanceof Enum) { |
||
| 37 | throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\Enum'); |
||
| 38 | } |
||
| 39 | |||
| 40 | $constraint->choices = null; |
||
| 41 | $constraint->callback = null; |
||
| 42 | |||
| 43 | if (!$constraint->enum) { |
||
| 44 | throw new ConstraintDefinitionException('"enum" must be specified on constraint Enum'); |
||
| 45 | } |
||
| 46 | |||
| 47 | if (!$this->enumRegistry->has($constraint->enum)) { |
||
| 48 | throw new ConstraintDefinitionException(sprintf( |
||
| 49 | '"enum" "%s" on constraint Enum does not exist', |
||
| 50 | $constraint->enum |
||
| 51 | )); |
||
| 52 | } |
||
| 53 | |||
| 54 | $constraint->choices = array_keys($this->enumRegistry->get($constraint->enum)->getChoices()); |
||
| 55 | |||
| 56 | parent::validate($value, $constraint); |
||
| 57 | } |
||
| 58 | } |
||
| 59 |