ArrayNode   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addNode() 0 11 2
A removeNode() 0 8 2
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