Completed
Push — master ( 02086d...3ba854 )
by Mike
03:44 queued 01:47
created

XerviceAtomicSettingNode   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 32
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A compile() 0 12 1
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Atomic\Business\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
}