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

NodeTag::isAwaitingChild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
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
 * @todo    handle tags like  <tag:clarkevans.com,2002:invoice>
11
 */
12
class NodeTag extends NodeActions
13
{
14
    public function isAwaitingChild(Node $node):bool
15
    {
16
        return is_null($this->value);
17
    }
18
19
    public function getTargetOnEqualIndent(Node &$node):Node
20
    {
21
        if (is_null($this->value)) {
22
            return $this;
23
        } else {
24
            return $this->getParent();
25
        }
26
    }
27
28
    /**
29
     * Builds a tag and its value (also built) and encapsulates them in a Tag object.
30
     *
31
     * @param array|object|null $parent The parent
32
     *
33
     * @return Tag|mixed The tag object of class Dallgoot\Yaml\Tag.
34
     */
35
    public function build(&$parent = null)
36
    {
37
        if ($this->getParent() instanceof NodeRoot && is_null($this->value)) {
38
            $this->getParent()->getYamlObject()->addTag($this->_tag);
39
            return;
40
        }
41
        $value = $this->value;
42
        if (is_null($parent) && isOneOf($value, ['NodeItem', 'NodeKey'])) {
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type null; however, parameter $obj of Dallgoot\Yaml\isOneOf() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

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

42
        if (is_null($parent) && isOneOf(/** @scrutinizer ignore-type */ $value, ['NodeItem', 'NodeKey'])) {
Loading history...
43
            $value = new NodeList($value);
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type Dallgoot\Yaml\NodeList; however, parameter $node of Dallgoot\Yaml\NodeList::__construct() does only seem to accept Dallgoot\Yaml\Node|null, maybe add an additional type check? ( Ignorable by Annotation )

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

43
            $value = new NodeList(/** @scrutinizer ignore-type */ $value);
Loading history...
44
        }
45
        if (TagFactory::isKnown($this->_tag)) {
0 ignored issues
show
Bug introduced by
It seems like $this->_tag can also be of type null; however, parameter $identifier of Dallgoot\Yaml\TagFactory::isKnown() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

45
        if (TagFactory::isKnown(/** @scrutinizer ignore-type */ $this->_tag)) {
Loading history...
46
            if ($value instanceof NodeLiterals) {
47
                $value = $value->value;
48
            }
49
            $built = TagFactory::transform($this->_tag, $value);
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type null; however, parameter $value of Dallgoot\Yaml\TagFactory::transform() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

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

49
            $built = TagFactory::transform($this->_tag, /** @scrutinizer ignore-type */ $value);
Loading history...
Bug introduced by
It seems like $this->_tag can also be of type null; however, parameter $identifier of Dallgoot\Yaml\TagFactory::transform() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

49
            $built = TagFactory::transform(/** @scrutinizer ignore-type */ $this->_tag, $value);
Loading history...
50
            if ($built instanceof Node || $built instanceof NodeList) {
51
                return $built->build($parent);
52
            }
53
            return $built;
54
        } else {
55
            return new Tag($this->_tag, is_null($value) ? null : $value->build($parent));
0 ignored issues
show
Bug introduced by
It seems like $this->_tag can also be of type null; however, parameter $tagName of Dallgoot\Yaml\Tag::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

55
            return new Tag(/** @scrutinizer ignore-type */ $this->_tag, is_null($value) ? null : $value->build($parent));
Loading history...
56
        }
57
    }
58
}