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

NormalizingNodeVisitor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A doEnterNode() 0 4 1
A doLeaveNode() 0 10 4
A getPriority() 0 4 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
/**
15
 * Performs equivalence transformations on the AST to ensure that
16
 * subsequent visitors do not need to be aware of different syntaxes.
17
 *
18
 * E.g. "foo" ~ "bar" ~ "baz" would become "foobarbaz"
19
 *
20
 * @author Johannes M. Schmitt <[email protected]>
21
 */
22
final class NormalizingNodeVisitor extends \Twig_BaseNodeVisitor
23
{
24
    /**
25
     * @param \Twig_Node        $node
26
     * @param \Twig_Environment $env
27
     *
28
     * @return \Twig_Node
29
     */
30 8
    protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
31
    {
32 8
        return $node;
33
    }
34
35
    /**
36
     * @param \Twig_Node        $node
37
     * @param \Twig_Environment $env
38
     *
39
     * @return \Twig_Node_Expression_Constant|\Twig_Node
40
     */
41 8
    protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
42
    {
43 8
        if ($node instanceof \Twig_Node_Expression_Binary_Concat
44 8
            && ($left = $node->getNode('left')) instanceof \Twig_Node_Expression_Constant
45 8
            && ($right = $node->getNode('right')) instanceof \Twig_Node_Expression_Constant) {
46 1
            return new \Twig_Node_Expression_Constant($left->getAttribute('value').$right->getAttribute('value'), $left->getTemplateLine());
47
        }
48
49 8
        return $node;
50
    }
51
52
    /**
53
     * @return int
54
     */
55 8
    public function getPriority()
56
    {
57 8
        return -3;
58
    }
59
}
60