ArrayNode::addNode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace Saxulum\JsonDocument;
4
5
class ArrayNode extends AbstractParent
6
{
7
    /**
8
     * @param  AbstractElement $node
9
     * @return void
10
     */
11
    public function addNode(AbstractElement $node)
12
    {
13
        if (in_array($node, $this->nodes, true)) {
14
            throw new \InvalidArgumentException("You can't add the same node twice!");
15
        }
16
17
        $this->checkNode($node);
18
        $this->removeNodeFromParent($node);
19
        Document::setProperty($node, 'parent', $this);
20
        $this->nodes[] = $node;
21
    }
22
23
    /**
24
     * @param  AbstractElement $node
25
     * @return void
26
     */
27
    public function removeNode(AbstractElement $node)
28
    {
29
        if (false !== $index = array_search($node, $this->nodes, true)) {
30
            throw new \InvalidArgumentException("Unknown node!");
31
        }
32
33
        Document::setProperty($node, 'parent', null);
34
    }
35
}
36