| Conditions | 6 |
| Paths | 6 |
| Total Lines | 22 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 6 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 20 | 8 | public function validate($value, Constraint $constraint) |
|
| 21 | { |
||
| 22 | 8 | if (!$constraint instanceof TwigSyntax) { |
|
| 23 | 1 | throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\TwigSyntax'); |
|
| 24 | } |
||
| 25 | |||
| 26 | 7 | if ($value === '' || $value === null) { |
|
| 27 | 2 | return; |
|
| 28 | } |
||
| 29 | |||
| 30 | 5 | $env = $this->getEnvironment($constraint); |
|
| 31 | try { |
||
| 32 | 5 | $tokeStream = $env->tokenize($value); |
|
| 33 | 4 | if ($constraint->parse) { |
|
| 34 | 3 | $env->parse($tokeStream); |
|
| 35 | 2 | } |
|
| 36 | 5 | } catch (\Twig_Error_Syntax $e) { |
|
| 37 | 2 | $this->context->addViolation($constraint->message, array( |
|
| 38 | 2 | '{{ value }}' => $this->formatValue($value), |
|
| 39 | 2 | )); |
|
| 40 | } |
||
| 41 | 5 | } |
|
| 42 | |||
| 53 |