Completed
Push — master ( b9e67a...92b65b )
by Cees-Jan
13s
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 declare(strict_types=1);
2
/**
3
 * This file is part of TwigView.
4
 *
5
 ** (c) 2014 Cees-Jan Kiewiet
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace WyriHaximus\TwigView\Lib\Twig\Node;
12
13
use Twig\Compiler;
14
use Twig\Node\Expression\AbstractExpression;
15
use Twig\Node\Node;
16
17
/**
18
 * Class Element.
19
 * @package WyriHaximus\TwigView\Lib\Twig\Node
20
 */
21
final class Element extends Node
22
{
23
    /**
24
     * Constructor.
25
     *
26
     * @param \Twig\Node\Expression\AbstractExpression $name    Name.
27
     * @param \Twig\Node\Expression\AbstractExpression $data    Data.
28
     * @param \Twig\Node\Expression\AbstractExpression $options Options.
29
     * @param string                                   $lineno  Linenumber.
30
     * @param string                                   $tag     Tag.
31
     */
32 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...
33
        AbstractExpression $name,
34
        AbstractExpression $data = null,
35
        AbstractExpression $options = null,
36
        $lineno = '',
37
        $tag = null
38
    ) {
39
        if ($data === null) {
40
            $data = new \Twig_Node_Expression_Array([], $lineno);
41
        }
42
43
        if ($options === null) {
44
            $options = new \Twig_Node_Expression_Array([], $lineno);
45
        }
46
47
        parent::__construct(
48
            [
49
                'name' => $name,
50
                'data' => $data,
51
                'options' => $options,
52
            ],
53
            [],
54
            $lineno,
55
            $tag
56
        );
57
    }
58
59
    /**
60
     * Compile node.
61
     *
62
     * @param \Twig\Compiler $compiler Compiler.
63
     *
64
     */
65
    public function compile(Compiler $compiler)
66
    {
67
        $compiler->addDebugInfo($this);
68
69
        $compiler->raw('echo $context[\'_view\']->element(');
70
        $compiler->subcompile($this->getNode('name'));
71
        $data = $this->getNode('data');
72
        if ($data !== null) {
73
            $compiler->raw(',');
74
            $compiler->subcompile($data);
75
        }
76
        $options = $this->getNode('options');
77
        if ($options !== null) {
78
            $compiler->raw(',');
79
            $compiler->subcompile($options);
80
        }
81
        $compiler->raw(");\n");
82
    }
83
}
84