Root::__construct()   A
last analyzed

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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dallgoot\Yaml\Nodes;
4
5
use Dallgoot\Yaml\NodeList;
6
use Dallgoot\Yaml\Types\YamlObject;
7
use Dallgoot\Yaml\Nodes\Generic\NodeGeneric;
8
9
/**
10
 *
11
 * @author  Stéphane Rebai <[email protected]>
12
 * @license Apache 2.0
13
 * @link    https://github.com/dallgoot/yaml
14
 */
15
class Root extends NodeGeneric
16
{
17
    private ?YamlObject $_yamlObject = null;
18
19
    public $value;
20
21 7
    public function __construct()
22
    {
23 7
        $this->value = new NodeList();
24
    }
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): YamlObject
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
}
62