AbstractParent::checkNode()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace Saxulum\JsonDocument;
4
5
abstract class AbstractParent extends AbstractElement
6
{
7
    /**
8
     * @var AbstractElement[]
9
     */
10
    protected $nodes = array();
11
12
    /**
13
     * @return AbstractElement[]
14
     */
15
    public function getNodes()
16
    {
17
        return $this->nodes;
18
    }
19
20
    /**
21
     * @param  int|string           $index node name or index, depends on object or array
22
     * @return AbstractElement|null
23
     */
24
    public function getNode($index)
25
    {
26
        return isset($this->nodes[$index]) ? $this->nodes[$index] : null;
27
    }
28
29
    /**
30
     * @param  AbstractElement $node
31
     * @return void
32
     */
33
    abstract public function addNode(AbstractElement $node);
34
35
    /**
36
     * @param  AbstractElement $node
37
     * @return void
38
     */
39
    abstract public function removeNode(AbstractElement $node);
40
41
    /**
42
     * @param  AbstractElement $node
43
     * @throws \Exception
44
     */
45 View Code Duplication
    protected function checkNode(AbstractElement $node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        if (null === $node->getName()) {
48
            throw new \Exception("Use the create<nodetype>Node on document!");
49
        }
50
51
        if (null === $node->getDocument() || $this->getDocument() !== $node->getDocument()) {
52
            throw new \Exception("Use the create<nodetype>Node on document!");
53
        }
54
    }
55
56
    /**
57
     * @param AbstractElement $node
58
     */
59
    protected function removeNodeFromParent(AbstractElement $node)
60
    {
61
        if (null !== $parent = $node->getParent()) {
62
            $parent->removeNode($node);
63
        }
64
    }
65
}
66