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