SetValue   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

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