LinearArrayAdapter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

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