Anchor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 21
ccs 9
cts 11
cp 0.8182
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 13 4
A isAwaitingChild() 0 3 1
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