Test Failed
Branch master (bee4a6)
by stéphane
14:37
created

Actions   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 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
    // public $anchor = '';
20
    // public $tag = '';
21
22
    public function __construct(string $nodeString, int $line)
23
    {
24
        parent::__construct($nodeString, $line);
25
        $trimmed = ltrim($nodeString);
26
        $pos = strpos($trimmed, ' ');
27
        $name = $trimmed;
28
        if (is_int($pos)) {
0 ignored issues
show
introduced by
The condition is_int($pos) is always true.
Loading history...
29
            $name = strstr($trimmed, ' ', true);
30
            $value = trim(substr($trimmed, $pos + 1));
31
            if ($value !== '') {
32
                $child = NodeFactory::get($value, $line);
33
                $child->indent = null;
34
                parent::add($child);
35
            }
36
        }
37
        if ($this instanceof Tag) {
38
            $this->tag = $name;
39
        } else {
40
            $this->anchor = $name;
41
        }
42
    }
43
}
44