RenderAddEmbedParamsNodeVisitor   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 4
Bugs 2 Features 1
Metric Value
eloc 14
c 4
b 2
f 1
dl 0
loc 54
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A leaveNode() 0 19 4
A enterNode() 0 3 1
A getPriority() 0 3 1
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\FrameworkExtraBundle\Twig;
8
9
use Twig_NodeVisitorInterface;
10
use Twig_NodeInterface;
11
use Twig_Environment;
12
13
/**
14
 * Class RenderAddEmbedParamsNodeVisitor
15
 *
16
 * @package Zicht\Bundle\FrameworkExtraBundle\Twig
17
 */
18
class RenderAddEmbedParamsNodeVisitor implements Twig_NodeVisitorInterface
19
{
20
    /**
21
     * Called before child nodes are visited.
22
     *
23
     * @param \Twig_NodeInterface $node The node to visit
24
     * @param \Twig_Environment   $env  The Twig environment instance
25
     *
26
     * @return \Twig_NodeInterface The modified node
27
     */
28
    public function enterNode(Twig_NodeInterface $node, Twig_Environment $env)
29
    {
30
        return $node;
31
    }
32
33
    /**
34
     * Called after child nodes are visited.
35
     *
36
     * @param \Twig_NodeInterface $node The node to visit
37
     * @param \Twig_Environment   $env  The Twig environment instance
38
     *
39
     * @return \Twig_NodeInterface The modified node
40
     */
41
    public function leaveNode(Twig_NodeInterface $node, Twig_Environment $env)
42
    {
43
        if ($node instanceof \Twig_Node_Expression_Function) {
44
            if ($node->getAttribute('name') === 'controller') {
45
                $args = $node->getNode('arguments');
46
                if (!$args->hasNode(1)) {
47
                    $args->setNode(1, new \Twig_Node_Expression_Array(array(), $node->getLine()));
0 ignored issues
show
Deprecated Code introduced by
The function Twig\Node\Node::getLine() has been deprecated: since 1.27 (to be removed in 2.0) ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

47
                    $args->setNode(1, new \Twig_Node_Expression_Array(array(), /** @scrutinizer ignore-deprecated */ $node->getLine()));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
48
                }
49
                $args->setNode(
50
                    1,
51
                    new \Twig_Node_Expression_Function(
52
                        'embed',
53
                        new \Twig_Node(array($args->getNode(1))),
54
                        $node->getLine()
0 ignored issues
show
Deprecated Code introduced by
The function Twig\Node\Node::getLine() has been deprecated: since 1.27 (to be removed in 2.0) ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

54
                        /** @scrutinizer ignore-deprecated */ $node->getLine()

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
55
                    )
56
                );
57
            }
58
        }
59
        return $node;
60
    }
61
62
    /**
63
     * Returns the priority for this visitor.
64
     *
65
     * Priority should be between -10 and 10 (0 is the default).
66
     *
67
     * @return integer The priority level
68
     */
69
    public function getPriority()
70
    {
71
        return 0;
72
    }
73
}
74