ArrayAdapter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A adapt() 0 5 1
A getArrayItems() 0 15 3
1
<?php
2
namespace ezTreeBuilder\Adapter;
3
4
use ezTreeBuilder\Base\AbstractAdapter;
5
use ezTreeBuilder\Base\Adapter;
6
7
class ArrayAdapter extends AbstractAdapter implements Adapter
8
{
9
    /**
10
     * Adapt a tree to Array
11
     * @return array
12
     */
13
    public function adapt()
14
    {
15
        $treeData = $this->getTree();
16
        return $this->getArrayItems($treeData);
17
    }
18
19
    /**
20
     * Loop throw the array and recursive call itself on children
21
     * @param array $items
22
     * @return array
23
     */
24
    private function getArrayItems($items)
25
    {
26
        $returnedArray = array();
27
        $iteration = 0;
28
        foreach ($items as $item) {
29
            $returnedArray[$iteration] = $item->getAsArray();
30
            if ($item->hasChildren() === true) {
31
                $returnedArray[$iteration]['children'] = $this->getArrayItems($item->getChildren());
32
            } else {
33
                $returnedArray[$iteration]['children'] = array();
34
            }
35
            $iteration++;
36
        }
37
        return $returnedArray;
38
    }
39
}
40