Completed
Push — master ( 3eacba...3b6a73 )
by stéphane
02:25
created

NodeCompactSequence::build()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
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 NodeCompactSequence extends Node
12
{
13 2
    public function __construct(string $nodeString, int $line)
14
    {
15 2
        parent::__construct($nodeString, $line);
16 2
        preg_match_all(Regex::SEQUENCE_VALUES, trim(substr(trim($nodeString), 1,-1)), $matches);
17 2
        foreach ($matches['item'] as $key => $item) {
18 2
            $i = new NodeItem('', $line);
19 2
            $i->indent = null;
20 2
            $itemValue = NodeFactory::get(trim($item));
21 2
            $itemValue->indent = null;
22 2
            $i->add($itemValue);
23 2
            $this->add($i);
24
        }
25 2
    }
26
27 1
    public function build(&$parent = null)
28
    {
29 1
        if (is_null($this->value)) {
30 1
            return null;
31
        }
32 1
        if ($this->value instanceof Node) {
33 1
            $this->value = new NodeList($this->value);
34 1
            $this->value->type = NodeList::SEQUENCE;
35
        }
36 1
        return new Compact($this->value->build());
0 ignored issues
show
Bug introduced by
It seems like $this->value->build() can also be of type boolean and double and integer and string; however, parameter $candidate of Dallgoot\Yaml\Compact::__construct() does only seem to accept array|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

36
        return new Compact(/** @scrutinizer ignore-type */ $this->value->build());
Loading history...
37
    }
38
}