CompactSequence   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 17
dl 0
loc 27
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A build() 0 11 3
1
<?php
2
3
namespace Dallgoot\Yaml\Nodes;
4
5
use Dallgoot\Yaml\NodeFactory;
6
use Dallgoot\Yaml\NodeList;
7
use Dallgoot\Yaml\Types\Compact;
8
use Dallgoot\Yaml\Regex;
9
use Dallgoot\Yaml\Nodes\Generic\NodeGeneric;
10
11
/**
12
 *
13
 * @author  Stéphane Rebai <[email protected]>
14
 * @license Apache 2.0
15
 * @link    https://github.com/dallgoot/yaml
16
 */
17
class CompactSequence extends NodeGeneric
18
{
19 2
    public function __construct(string $nodeString, ?int $line)
20
    {
21 2
        parent::__construct($nodeString, $line);
22 2
        preg_match_all(Regex::SEQUENCE_VALUES, trim(substr(trim($nodeString), 1, -1)), $matches);
23 2
        foreach ($matches['item'] as $key => $item) {
24 2
            $i = new Item('', (int) $line);
25 2
            $i->indent = null;
26 2
            $itemValue = NodeFactory::get(trim($item));
27 2
            $itemValue->indent = null;
28 2
            $i->add($itemValue);
29 2
            $this->add($i);
30
        }
31
    }
32
33 1
    public function build(&$parent = null): ?Compact
34
    {
35 1
        if (is_null($this->value)) {
36 1
            return null;
37
        }
38 1
        if ($this->value instanceof NodeGeneric) {
39 1
            $this->value = new NodeList($this->value);
40 1
            $this->value->type = NodeList::SEQUENCE;
41
        }
42 1
        $arr = (array) $this->value->build();
43 1
        return new Compact($arr);
44
    }
45
}
46