Completed
Push — master ( 3ba854...8ff2cd )
by Mike
03:56
created

XerviceAtomicSettingNode::compile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 12
ccs 9
cts 9
cp 1
crap 1
rs 9.9666
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Atomic\Communication\Twig\Extension\Node;
6
7
8
use Twig_Compiler;
9
use Twig_Node_Expression;
10
11
class XerviceAtomicSettingNode extends \Twig_Node
12
{
13
    /**
14
     * XerviceAtomicSettingNode constructor.
15
     *
16
     * @param $name
17
     * @param \Twig_Node_Expression $value
18
     * @param $line
19
     * @param null $tag
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $tag is correct as it would always require null to be passed?
Loading history...
20
     */
21 1
    public function __construct($name, Twig_Node_Expression $value, $line, $tag = null)
22
    {
23 1
        parent::__construct(array('value' => $value), array('name' => $name), $line, $tag);
24 1
    }
25
26
    /**
27
     * @param \Twig_Compiler $compiler
28
     *
29
     * @return \Twig_Compiler
30
     */
31 1
    public function compile(Twig_Compiler $compiler): Twig_Compiler
32
    {
33 1
        $setting = "'" . $this->getAttribute('name') . "'";
34
35
        return $compiler
36 1
            ->addDebugInfo($this)
37 1
            ->raw('if (!array_key_exists(' . $setting . ', $context)) {')
38 1
            ->raw('$context[' . $setting . '] = [];')
39 1
            ->raw('}')
40 1
            ->raw('$context[' . $setting . '] = array_replace_recursive(')
41 1
            ->subcompile($this->getNode('value'))
42 1
            ->raw(', $context[' . $setting . ']);');
43
    }
44
45
}