Completed
Push — 4.x-fix-nodes ( 1f82a2 )
by Cees-Jan
02:03
created

Element::__construct()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 26
Code Lines 16

Duplication

Lines 26
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 26
loc 26
ccs 0
cts 24
cp 0
rs 8.8571
cc 3
eloc 16
nc 4
nop 5
crap 12
1
<?php
2
3
/**
4
 * This file is part of TwigView.
5
 *
6
 ** (c) 2014 Cees-Jan Kiewiet
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace WyriHaximus\TwigView\Lib\Twig\Node;
12
13
/**
14
 * Class Element
15
 * @package WyriHaximus\TwigView\Lib\Twig\Node
16
 */
17
class Element extends \Twig_Node
18
{
19
    /**
20
     * Constructor.
21
     *
22
     * @param \Twig_Node_Expression $name    Name.
23
     * @param \Twig_Node_Expression $data    Data.
24
     * @param \Twig_Node_Expression $options Options.
25
     * @param string                $lineno  Linenumber.
26
     * @param string                $tag     Tag.
27
     */
28 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
        \Twig_Node_Expression $name,
30
        \Twig_Node_Expression $data = null,
31
        \Twig_Node_Expression $options = null,
32
        $lineno = '',
33
        $tag = null
34
    ) {
35
        if ($data === null) {
36
            $data = new \Twig_Node_Expression_Array([], $lineno);
37
        }
38
39
        if ($options === null) {
40
            $options = new \Twig_Node_Expression_Array([], $lineno);
41
        }
42
43
        parent::__construct(
44
            [
45
                'name' => $name,
46
                'data' => $data,
47
                'options' => $options,
48
            ],
49
            [],
50
            $lineno,
51
            $tag
52
        );
53
    }
54
55
    /**
56
     * Compile node.
57
     *
58
     * @param \Twig_Compiler $compiler Compiler.
59
     *
60
     * @return void
61
     */
62
    public function compile(\Twig_Compiler $compiler)
63
    {
64
        $compiler->addDebugInfo($this);
65
66
        $compiler->raw('echo $context[\'_view\']->element(');
67
        $compiler->subcompile($this->getNode('name'));
68
        $data = $this->getNode('data');
69
        if ($data !== null) {
70
            $compiler->raw(',');
71
            $compiler->subcompile($data);
72
        }
73
        $options = $this->getNode('options');
74
        if ($options !== null) {
75
            $compiler->raw(',');
76
            $compiler->subcompile($options);
77
        }
78
        $compiler->raw(");\n");
79
    }
80
}
81