SyntaxCheckNodeVisitor   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
D doEnterNode() 0 27 9
A doLeaveNode() 0 6 1
A getPriority() 0 4 1
1
<?php
2
3
namespace MewesK\TwigExcelBundle\Twig\NodeVisitor;
4
5
use MewesK\TwigExcelBundle\Twig\Node\SyntaxAwareNodeInterface;
6
use MewesK\TwigExcelBundle\Twig\NodeHelper;
7
use Twig_BaseNodeVisitor;
8
use Twig_Environment;
9
use Twig_Error_Syntax;
10
use Twig_Node;
11
use Twig_Node_Block;
12
use Twig_Node_Macro;
13
14
/**
15
 * Class SyntaxCheckNodeVisitor
16
 *
17
 * @package MewesK\TwigExcelBundle\Twig\NodeVisitor
18
 */
19
class SyntaxCheckNodeVisitor extends Twig_BaseNodeVisitor
20
{
21
    /**
22
     * @var array
23
     */
24
    protected $path = [];
25
26
    /**
27
     * {@inheritdoc}
28
     *
29
     * @throws Twig_Error_Syntax
30
     */
31
    protected function doEnterNode(Twig_Node $node, Twig_Environment $env)
32
    {
33
        if (($node instanceof Twig_Node_Block || $node instanceof Twig_Node_Macro) && !$node->hasAttribute('twigExcelBundle') && NodeHelper::checkContainsXlsNode($node)) {
0 ignored issues
show
Bug introduced by
The class Twig_Node_Block does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
Bug introduced by
The class Twig_Node_Macro does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
34
            if ($node instanceof Twig_Node_Block) {
0 ignored issues
show
Bug introduced by
The class Twig_Node_Block does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
35
                throw new Twig_Error_Syntax('Block tags do not work together with Twig tags provided by TwigExcelBundle. Please use \'xlsblock\' instead.');
36
            }
37
            elseif ($node instanceof Twig_Node_Macro) {
0 ignored issues
show
Bug introduced by
The class Twig_Node_Macro does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
38
                throw new Twig_Error_Syntax('Macro tags do not work together with Twig tags provided by TwigExcelBundle. Please use \'xlsmacro\' instead.');
39
            }
40
        }
41
        elseif ($node instanceof SyntaxAwareNodeInterface) {
42
            /**
43
             * @var SyntaxAwareNodeInterface $node
44
             */
45
            try {
46
                NodeHelper::checkAllowedParents($node, $this->path);
47
            } catch(Twig_Error_Syntax $e) {
0 ignored issues
show
Bug introduced by
The class Twig_Error_Syntax does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
48
                // reset path since throwing an error prevents doLeaveNode to be called
49
                $this->path = [];
50
                throw $e;
51
            }
52
        }
53
54
        $this->path[] = get_class($node);
55
56
        return $node;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    protected function doLeaveNode(Twig_Node $node, Twig_Environment $env)
63
    {
64
        array_pop($this->path);
65
66
        return $node;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function getPriority()
73
    {
74
        return 0;
75
    }
76
}
77