Completed
Push — master ( c45521...844759 )
by stéphane
08:22
created

NodeCompactSequence::build()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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
    public function __constructor(string $nodeString, int $line)
14
    {
15
        parent::__construct($nodeString, $line);
16
        $this->value = new NodeList();
17
        preg_match_all(Regex::SEQUENCE_VALUES, trim(substr(ltrim($nodeString), 1,-1)), $matches);
18
        foreach ($matches['item'] as $key => $item) {
19
            $this->value->push(new NodeItem('- '.$item, $line));
20
        }
21
    }
22
23
    public function build(&$parent = null)
24
    {
25
        $out = $parent ?? [];
26
        $tmp = $this->value instanceof Node ? new NodeList($this->value) : $this->value;
27
        foreach ($tmp as $child) {
28
            $child->build($out);
29
        }
30
        return new Compact($out);
31
    }
32
}