GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( dea5e9...4057a0 )
by Mewes
02:21
created

SyntaxCheckNodeVisitor::doEnterNode()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 5
nop 2
1
<?php
2
3
namespace MewesK\TwigSpreadsheetBundle\Twig\NodeVisitor;
4
5
use MewesK\TwigSpreadsheetBundle\Twig\Node\BaseNode;
6
7
/**
8
 * Class SyntaxCheckNodeVisitor.
9
 */
10
class SyntaxCheckNodeVisitor extends \Twig_BaseNodeVisitor
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $path = [];
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function getPriority()
21
    {
22
        return 0;
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     *
28
     * @throws \Twig_Error_Syntax
29
     */
30
    protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
31
    {
32
        if ($node instanceof BaseNode) {
33
            /*
34
             * @var BaseNode $node
35
             */
36
            try {
37
                $this->checkAllowedParents($node);
38
            } catch (\Twig_Error_Syntax $e) {
39
                // reset path since throwing an error prevents doLeaveNode to be called
40
                $this->path = [];
41
                throw $e;
42
            }
43
        }
44
45
        $this->path[] = $node !== null ? get_class($node) : null;
46
47
        return $node;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    protected function doLeaveNode(\Twig_Node $node, \ Twig_Environment $env)
54
    {
55
        array_pop($this->path);
56
57
        return $node;
58
    }
59
60
    /**
61
     * @param BaseNode $node
62
     *
63
     * @throws \Twig_Error_Syntax
64
     */
65
    private function checkAllowedParents(BaseNode $node)
66
    {
67
        $parentName = null;
68
69
        foreach (array_reverse($this->path) as $className) {
70
            if (strpos($className, 'MewesK\\TwigSpreadsheetBundle\\Twig\\Node\\') === 0) {
71
                $parentName = $className;
72
                break;
73
            }
74
        }
75
76
        if ($parentName === null) {
77
            return;
78
        }
79
80
        foreach ($node->getAllowedParents() as $className) {
81
            if ($className === $parentName) {
82
                return;
83
            }
84
        }
85
86
        throw new \Twig_Error_Syntax(sprintf('Node "%s" is not allowed inside of Node "%s".', get_class($node), $parentName));
87
    }
88
}
89