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

NodeRoot   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
wmc 9
eloc 17
dl 0
loc 46
ccs 20
cts 21
cp 0.9524
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRoot() 0 3 1
A build() 0 3 1
A __construct() 0 3 1
A getYamlObject() 0 6 2
A getParent() 0 6 2
A buildFinal() 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 NodeRoot extends Node
12
{
13
    /** @var null|YamlObject */
14
    private $_yamlObject;
15
    /** @var NodeList */
16
    public $value;
17
18 7
    public function __construct()
19
    {
20 7
        $this->value = new NodeList();
21 7
    }
22
23 1
    public function getParent(int $indent = null, $type = 0):Node
24
    {
25 1
        if ($this->_parent !== null) {
26 1
            throw new \ParseError(__CLASS__." can NOT have a parent, something's wrong", 1);
27
        }
28 1
        return $this;
29
    }
30
31 1
    public function getRoot():Node
32
    {
33 1
        return $this;
34
    }
35
36 2
    public function getYamlObject():YamlObject
37
    {
38 2
        if ($this->_yamlObject) {
39 1
            return $this->_yamlObject;
40
        }
41 1
        throw new \Exception("YamlObject has not been set yet", 1);
42
    }
43
44 1
    public function build(&$parent = null)
45
    {
46 1
        return $this->buildFinal($parent);
47
    }
48
49 3
    private function buildFinal(YamlObject $yamlObject):YamlObject
50
    {
51 3
        $this->_yamlObject = $yamlObject;
52 3
        $this->value->setIteratorMode(NodeList::IT_MODE_DELETE);
53 3
        foreach ($this->value as $key => $child) {
54
            $child->build($yamlObject);
55
        }
56 3
        return $yamlObject;
57
    }
58
}