Anchor::build()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.1755

Importance

Changes 0
Metric Value
cc 4
eloc 11
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 13
ccs 7
cts 9
cp 0.7778
crap 4.1755
rs 9.9
1
<?php
2
3
namespace Dallgoot\Yaml\Nodes;
4
5
use Dallgoot\Yaml\Nodes\Generic\Actions;
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 Anchor extends Actions
15
{
16 1
    public function &build(&$parent = null)
17
    {
18 1
        $name = substr((string) $this->anchor, 1);
19 1
        $yamlObject = $this->getRoot()->getYamlObject();
20 1
        if (str_starts_with((string) $this->anchor, "*")) {
21
            try {
22 1
                return $yamlObject->getReference($name);
23
            } catch (\Throwable $e) {
24
                throw new \ParseError("Unknown anchor : '$name' this:" . $this->anchor, 1, $e);
25
            }
26
        } else {
27 1
            $built = is_null($this->value) ? null : $this->value->build($parent);
28 1
            return $yamlObject->addReference($name, $built);
29
        }
30
    }
31
32 1
    public function isAwaitingChild(NodeGeneric $node): bool
33
    {
34 1
        return is_null($this->value);
35
    }
36
}
37