Completed
Push — master ( cb2703...d9d040 )
by Tobias
12:13
created

RemovingNodeVisitor::doEnterNode()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 6
nc 3
nop 2
crap 5
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\Bundle\Twig\Visitor;
13
14
/**
15
 * Removes translation metadata filters from the AST.
16
 *
17
 * @author Johannes M. Schmitt <[email protected]>
18
 */
19
final class RemovingNodeVisitor extends \Twig_BaseNodeVisitor
20
{
21
    /**
22
     * @var bool
23
     */
24
    private $enabled = true;
25
26
    /**
27
     * @param $bool
28
     */
29
    public function setEnabled($bool)
30
    {
31
        $this->enabled = (bool) $bool;
32
    }
33
34
    /**
35
     * @param \Twig_Node        $node
36
     * @param \Twig_Environment $env
37
     *
38
     * @return \Twig_Node
39
     */
40 8
    protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
41
    {
42 8
        if ($this->enabled && $node instanceof \Twig_Node_Expression_Filter) {
43 6
            $name = $node->getNode('filter')->getAttribute('value');
44
45 6
            if ('desc' === $name || 'meaning' === $name) {
46 2
                return $this->enterNode($node->getNode('node'), $env);
47
            }
48
        }
49
50 8
        return $node;
51
    }
52
53
    /**
54
     * @param \Twig_Node        $node
55
     * @param \Twig_Environment $env
56
     *
57
     * @return \Twig_Node
58
     */
59 8
    protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
60
    {
61 8
        return $node;
62
    }
63
64
    /**
65
     * @return int
66
     */
67 8
    public function getPriority()
68
    {
69 8
        return -1;
70
    }
71
}
72