| Conditions | 5 |
| Paths | 4 |
| Total Lines | 19 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 5.0342 |
| Changes | 5 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 16 | public function validate(mixed $value, Constraint $constraint): void |
||
| 17 | { |
||
| 18 | if (!$constraint instanceof Dictionary) { |
||
| 19 | 5 | throw new UnexpectedTypeException($constraint, Dictionary::class); |
|
| 20 | } |
||
| 21 | 5 | ||
| 22 | 5 | if (null === $value || '' === $value) { |
|
| 23 | return; |
||
| 24 | 4 | } |
|
| 25 | |||
| 26 | 4 | $dictionary = $this->collection[$constraint->name]; |
|
| 27 | 1 | $values = $dictionary->getKeys(); |
|
| 28 | |||
| 29 | if (!\in_array($value, $values, true)) { |
||
| 30 | 3 | $this->context->addViolation( |
|
| 31 | $constraint->message, |
||
| 32 | [ |
||
| 33 | '{{ key }}' => $this->varToString($value), |
||
| 34 | 3 | '{{ keys }}' => implode(', ', array_map($this->varToString(...), $values)), |
|
| 35 | 3 | ] |
|
| 71 |