Passed
Push — master ( 844759...f0c5ab )
by stéphane
07:52
created

NodeDocStart::build()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 14
rs 9.6111
c 0
b 0
f 0
cc 5
nc 5
nop 1
1
<?php
2
3
namespace Dallgoot\Yaml;
4
5
/**
6
 *
7
 * @author  Stéphane Rebai <[email protected]>
8
 * @license Apache 2.0
9
 * @link    TODO : url to specific online doc
10
 */
11
class NodeDocStart extends Node
12
{
13
    public function __construct(string $nodeString, int $line)
14
    {
15
        parent::__construct($nodeString, $line);
16
        $rest = substr(ltrim($nodeString), 3);
17
        if (!empty($rest)) {
18
            $n = NodeFactory::get($rest, $line);
19
            $n->indent = null;
20
            $this->add($n);
21
        }
22
    }
23
24
    public function add(Node $child):Node
25
    {
26
        if ($this->value instanceof Node) {
27
            return $this->value->add($child);
28
        } else {
29
            return parent::add($child);
30
        }
31
    }
32
33
    public function build(&$parent = null)
34
    {
35
        if (is_null($parent)) {
36
            throw new Exception(__METHOD__." expects a YamlObject as parent", 1);
0 ignored issues
show
Bug introduced by
The type Dallgoot\Yaml\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
37
        }
38
        if (is_null($this->value)) {
39
            return null;
40
        } else {
41
            if ($this->value instanceof NodeTag){
42
                $parent->addTag($this->value->_tag);
43
                $this->value->build($parent);
44
            } else {
45
                $text = $this->value->build($parent);
46
                !is_null($text) && $parent->setText($text);
47
            }
48
        }
49
    }
50
51
    public function isAwaitingChild(Node $node):bool
52
    {
53
        return $this->value && isOneOf($this->value, ['NodeRefDef', 'NodeLit', 'NodeLitFolded']);
54
    }
55
56
    public function getTargetOnEqualIndent(Node &$node):Node
57
    {
58
        if ($this->value && $this->value->isAwaitingChild($node)) {
0 ignored issues
show
Bug introduced by
The method isAwaitingChild() does not exist on Dallgoot\Yaml\NodeList. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
        if ($this->value && $this->value->/** @scrutinizer ignore-call */ isAwaitingChild($node)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
            return $this->value;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->value could return the type Dallgoot\Yaml\NodeList which is incompatible with the type-hinted return Dallgoot\Yaml\Node. Consider adding an additional type-check to rule them out.
Loading history...
60
        }
61
        return $this->getParent();
62
    }
63
}