Passed
Push — master ( f81cc4...5281ab )
by stéphane
04:50
created

Root   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 95.24%

Importance

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

6 Methods

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