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

NodeRoot::getRoot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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
}