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

NodeCompactMapping::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
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 NodeCompactMapping 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::MAPPING_VALUES, trim(substr(trim($nodeString), 1,-1)), $matches);
17 2
        foreach ($matches['k'] as $index => $property) {
18 2
            $pair = $property.': '.trim($matches['v'][$index]);
19 2
            $child = NodeFactory::get($pair, $line);
20 2
            $child->indent = null;
21 2
            $this->add($child);
22
        }
23 2
    }
24
25 1
    public function build(&$parent = null)
26
    {
27 1
        if (is_null($this->value)) {
28 1
            return null;
29
        }
30 1
        if ($this->value instanceof Node) {
31 1
            $this->value = new NodeList($this->value);
32 1
            $this->value->type = NodeList::MAPPING;
33
        }
34 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

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