Conditions | 4 |
Paths | 4 |
Total Lines | 24 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
15 | public function validate($value, Constraint $constraint) |
||
16 | { |
||
17 | $context = $this->context; |
||
18 | if (!is_string($value)) { |
||
19 | $context |
||
20 | ->buildViolation($constraint->illegalValueMessage) |
||
21 | ->setParameter('{{ type }}', gettype($value)) |
||
22 | ->addViolation(); |
||
23 | return; |
||
24 | } |
||
25 | $option = Registry::getInstance()->find($value); |
||
26 | if (!$option) { |
||
27 | $context |
||
28 | ->buildViolation($constraint->missingOptionMessage) |
||
29 | ->setParameter('{{ name }}', $value) |
||
30 | ->addViolation(); |
||
31 | return; |
||
32 | } |
||
33 | if ($option->getId() !== $value) { |
||
34 | $context |
||
35 | ->buildViolation($constraint->message) |
||
36 | ->setParameter('{{ name }}', $value) |
||
37 | ->setParameter('{{ id }}', $option->getId()) |
||
38 | ->addViolation(); |
||
39 | } |
||
42 |