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( |
|
|
|
|
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
|
|
|
|
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.