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

NodeCompactSequence   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __constructor() 0 7 2
A build() 0 8 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
    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
}