| Conditions | 5 |
| Paths | 4 |
| Total Lines | 23 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 5.0073 |
| Changes | 5 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 24 | 4 | public function validate($value, Constraint $constraint): void |
|
| 25 | { |
||
| 26 | 4 | if (!$constraint instanceof Dictionary) { |
|
| 27 | 1 | throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Dictionary'); |
|
| 28 | } |
||
| 29 | |||
| 30 | 3 | if (null === $value || '' === $value) { |
|
| 31 | return; |
||
| 32 | } |
||
| 33 | |||
| 34 | 3 | $dictionary = $this->dictionaries[$constraint->name]; |
|
| 35 | 3 | $values = $dictionary->getKeys(); |
|
| 36 | |||
| 37 | 3 | if (!\in_array($value, $values, true)) { |
|
| 38 | 2 | $this->context->addViolation( |
|
| 39 | 2 | $constraint->message, |
|
| 40 | [ |
||
| 41 | 2 | '{{ key }}' => $this->varToString($value), |
|
| 42 | 2 | '{{ keys }}' => implode( |
|
| 43 | 2 | ', ', |
|
| 44 | 2 | array_map( |
|
| 45 | 2 | [$this, 'varToString'], |
|
| 46 | $values |
||
| 47 | ) |
||
| 81 |