AbstractNode::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Saxulum\JsonDocument;
4
5
abstract class AbstractNode
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $name;
11
12
    /**
13
     * @var DocumentInterface
14
     */
15
    protected $document;
16
17
    /**
18
     * @var null|AbstractParent
19
     */
20
    protected $parent;
21
22
    /**
23
     * @var \ReflectionClass
24
     */
25
    protected $rAbstractNode;
26
27
    /**
28
     * @return string
29
     */
30
    public function getName()
31
    {
32
        return $this->name;
33
    }
34
35
    /**
36
     * @return DocumentInterface
37
     */
38
    public function getDocument()
39
    {
40
        return $this->document;
41
    }
42
43
    /**
44
     * @return null|AbstractParent
45
     */
46
    public function getParent()
47
    {
48
        return $this->parent;
49
    }
50
51
    /**
52
     * @return null|AbstractNode
53
     */
54
    abstract public function previousSibling();
55
56
    /**
57
     * @return null|AbstractNode
58
     */
59
    abstract public function nextSibling();
60
61
    /**
62
     * @param  AbstractNode[]     $nodes
63
     * @param  int                $rel
64
     * @return null|AbstractNode
65
     */
66
    protected function getSibling(array $nodes, $rel)
67
    {
68
        $nodeKeys = array_keys($nodes);
69
        $nodeKey = array_search($this, $nodes, true);
70
        $nodeIndex = array_search($nodeKey, $nodeKeys, true);
71
        $prevNodeIndex = $nodeIndex + $rel;
72
73
        if (!isset($nodeKeys[$prevNodeIndex])) {
74
            return null;
75
        }
76
77
        $prevNodeIndex = $nodeKeys[$prevNodeIndex];
78
79
        return $nodes[$prevNodeIndex];
80
    }
81
}
82