ObjectNodeToArrayHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getArray() 0 18 4
A isResponsible() 0 4 1
1
<?php
2
3
namespace Saxulum\JsonDocument\NodeToArray;
4
5
use Saxulum\JsonDocument\AbstractNode;
6
use Saxulum\JsonDocument\ObjectNode;
7
8
class ObjectNodeToArrayHandler extends AbstractNodeToArrayHandler
9
{
10
    /**
11
     * @param  AbstractNode $node
12
     * @param  bool         $embedded
13
     * @return array
14
     */
15
    public function getArray(AbstractNode $node, $embedded = false)
16
    {
17
        if (!$node instanceof ObjectNode) {
18
            throw new \InvalidArgumentException("Invalid node type!");
19
        }
20
21
        $array = array();
22
23
        foreach ($node->getAttributes() as $attribute) {
24
            $array[$attribute->getFormattedName()] =$this->getMainHandler()->getArray($attribute, true);
25
        }
26
27
        foreach ($node->getNodes() as $name => $childNode) {
28
            $array[$name] = $this->getMainHandler()->getArray($childNode, true);
29
        }
30
31
        return $array;
32
    }
33
34
    /**
35
     * @param  AbstractNode $node
36
     * @return bool
37
     */
38
    public function isResponsible(AbstractNode $node)
39
    {
40
        return $node instanceof ObjectNode;
41
    }
42
}
43