Passed
Push — master ( 42571c...f8295f )
by stéphane
09:20
created

Anchor   A

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
/**
6
 *
7
 * @author  Stéphane Rebai <[email protected]>
8
 * @license Apache 2.0
9
 * @link    https://github.com/dallgoot/yaml
10
 */
11
class Anchor extends Actions
12
{
13 1
    public function &build(&$parent = null)
14
    {
15 1
        $name = substr($this->anchor, 1);
16 1
        $yamlObject = $this->getRoot()->getYamlObject();
17 1
        if ($this->anchor[0] === "*") {
18
            try {
19 1
                return $yamlObject->getReference($name);
20
            } catch (\Throwable $e) {
21
                throw new \ParseError("Unknown anchor : '$name' this:".$this->anchor,1,$e);
22
            }
23
        } else {
24 1
            $built = is_null($this->value) ? null : $this->value->build($parent);
25 1
            return $yamlObject->addReference($name, $built);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $yamlObject->addReference($name, $built) targeting Dallgoot\Yaml\YamlObject::addReference() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
26
        }
27
    }
28
29 1
    public function isAwaitingChild(NodeGeneric $node):bool
30
    {
31 1
        return is_null($this->value);
32
    }
33
}