Completed
Push — master ( c6ecf3...3eacba )
by stéphane
02:27
created

NodeSetValue   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 11
dl 0
loc 29
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 5 2
A isAwaitingChild() 0 3 2
A __construct() 0 8 2
1
<?php
2
3
namespace Dallgoot\Yaml;
4
5
/**
6
 *
7
 * @author  Stéphane Rebai <[email protected]>
8
 * @license Apache 2.0
9
 * @link    TODO : url to specific online doc
10
 */
11
class NodeSetValue extends Node
12
{
13 3
    public function __construct(string $nodeString, int $line)
14
    {
15 3
        parent::__construct($nodeString, $line);
16 3
        $v = substr(ltrim($nodeString), 1);
17 3
        if (!empty($v)) {
18 3
            $value = NodeFactory::get($v, $line);
19 3
            $value->indent = null;
20 3
            $this->add($value);
21
        }
22 3
    }
23
24
    /**
25
     * Builds a set value.
26
     *
27
     * @param Node   $node   The node of type YAML::SET_VALUE
28
     * @param object $parent The parent (the document object or any previous object created through a mapping key)
29
     */
30 1
    public function build(&$parent = null)
31
    {
32 1
        $prop = array_keys(get_object_vars($parent));
33 1
        $key = end($prop);
34 1
        $parent->{$key} = is_null($this->value) ? null: $this->value->build();
35 1
    }
36
37 1
    public function isAwaitingChild(Node $node):bool
38
    {
39 1
        return is_null($this->value) || $this->getDeepestNode()->isAwaitingChild($node);
40
    }
41
}