Conditions | 5 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | public function validate($value, Constraint $constraint): void |
||
17 | { |
||
18 | // custom constraints should ignore null and empty values to allow |
||
19 | // other constraints (NotBlank, NotNull, etc.) take care of that |
||
20 | if ('' === $value || null === $value) { |
||
21 | return; |
||
22 | } |
||
23 | |||
24 | if (!$constraint instanceof Barcode) { |
||
25 | throw new InvalidArgumentException(sprintf('This validator only supports the %s constraint', Barcode::class)); |
||
26 | } |
||
27 | |||
28 | $validator = new ActualBarcodeValidator($value); |
||
29 | $valid = (bool) $validator->isValid(); |
||
30 | |||
31 | if (!$valid) { |
||
32 | $this->context->buildViolation($constraint->message) |
||
33 | ->setParameter('{{ string }}', $value) |
||
34 | ->addViolation(); |
||
35 | } |
||
36 | |||
37 | unset($validator); |
||
38 | } |
||
40 |