RenderObjectNode::addGetTemplate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 2
eloc 16
nc 2
nop 1
1
<?php
2
3
namespace Psi\Bundle\ObjectRender\Twig\Node;
4
5
class RenderObjectNode extends \Twig_Node_Expression_Function
6
{
7
    public function compile(\Twig_Compiler $compiler)
8
    {
9
        $compiler->addDebugInfo($this);
10
        $this->addGetTemplate($compiler);
11
        $compiler->raw('->display(');
12
        $this->addTemplateArguments($compiler);
13
        $compiler->raw(')');
14
    }
15
16
    protected function addGetTemplate(\Twig_Compiler $compiler)
17
    {
18
        $args = $this->getNode('arguments');
19
20
        if (!$args->hasNode(0)) {
21
            throw new \Twig_Error_Runtime(sprintf(
22
                'Function "%s" requires an object as its first argument',
23
                $this->getAttribute('name')
24
            ));
25
        }
26
        $objectArg = $args->getNode(0);
27
        $compiler
28
             ->write('$this->loadTemplate(')
29
             ->write('$this->env->getExtension("Psi\Bundle\ObjectRender\Twig\ObjectRenderExtension")->locateFile(')
30
             ->subcompile($objectArg)
31
             ->raw('), ')
32
             ->repr($this->getAttribute('name'))
33
             ->raw(', ')
34
             ->repr($this->getLine())
0 ignored issues
show
Deprecated Code introduced by
The method Twig_Node::getLine() has been deprecated with message: since 1.27 (to be removed in 2.0)

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

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

Loading history...
35
             ->raw(')');
36
    }
37
38
    protected function addTemplateArguments(\Twig_Compiler $compiler)
39
    {
40
        $object = $this->getNode('arguments');
41
        $object = $object->getNode(0);
42
        $compiler->raw('[ "object" => ');
43
        $compiler->subcompile($object);
44
        $compiler->raw(']');
45
    }
46
}
47