Actions::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 19
ccs 15
cts 15
cp 1
rs 9.7666
c 0
b 0
f 0
cc 4
nc 6
nop 2
crap 4
1
<?php
2
3
namespace Dallgoot\Yaml\Nodes\Generic;
4
5
use Dallgoot\Yaml\Nodes\Generic\NodeGeneric;
6
use Dallgoot\Yaml\NodeFactory;
7
use Dallgoot\Yaml\Nodes\Tag;
8
9
/**
10
 * Common parent to NodeAnchor, NodeTag
11
 * Extract identifier (tag or anchor) and attach its value (another Node)
12
 *
13
 * @author  Stéphane Rebai <[email protected]>
14
 * @license Apache 2.0
15
 * @link    https://github.com/dallgoot/yaml
16
 */
17
abstract class Actions extends NodeGeneric
18
{
19
20 2
    public function __construct(string $nodeString, int $line)
21
    {
22 2
        parent::__construct($nodeString, $line);
23 2
        $trimmed = ltrim($nodeString);
24 2
        $pos = strpos($trimmed, ' ');
25 2
        $name = $trimmed;
26 2
        if (is_int($pos)) {
0 ignored issues
show
introduced by
The condition is_int($pos) is always true.
Loading history...
27 2
            $name = strstr($trimmed, ' ', true);
28 2
            $value = trim(substr($trimmed, $pos + 1));
29 2
            if ($value !== '') {
30 2
                $child = NodeFactory::get($value, $line);
31 2
                $child->indent = null;
32 2
                parent::add($child);
33
            }
34
        }
35 2
        if ($this instanceof Tag) {
36 1
            $this->tag = $name;
37
        } else {
38 2
            $this->anchor = $name;
39
        }
40
    }
41
}
42