NodeToArray   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

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