RemovingNodeVisitor::getPriority()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
use Twig\Environment;
15
use Twig\Node\Expression\FilterExpression;
16
use Twig\Node\Node;
17
use Twig\NodeVisitor\AbstractNodeVisitor;
18
19
/**
20
 * Removes translation metadata filters from the AST.
21
 *
22
 * @author Johannes M. Schmitt <[email protected]>
23
 */
24
final class RemovingNodeVisitor extends AbstractNodeVisitor
25
{
26
    /**
27
     * @var bool
28
     */
29
    private $enabled = true;
30
31
    public function setEnabled(bool $bool): void
32
    {
33
        $this->enabled = $bool;
34
    }
35
36 3
    protected function doEnterNode(Node $node, Environment $env): Node
37
    {
38 3
        if ($this->enabled && $node instanceof FilterExpression) {
39 2
            $name = $node->getNode('filter')->getAttribute('value');
40
41 2
            if ('desc' === $name || 'meaning' === $name) {
42 2
                return $this->enterNode($node->getNode('node'), $env);
43
            }
44
        }
45
46 3
        return $node;
47
    }
48
49 3
    protected function doLeaveNode(Node $node, Environment $env): Node
50
    {
51 3
        return $node;
52
    }
53
54 3
    public function getPriority(): int
55
    {
56 3
        return -1;
57
    }
58
}
59