RemovingNodeVisitor   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 76.92%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 10
c 4
b 1
f 0
dl 0
loc 33
ccs 10
cts 13
cp 0.7692
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setEnabled() 0 3 1
A getPriority() 0 3 1
A doEnterNode() 0 11 5
A doLeaveNode() 0 3 1
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