LinearArrayAdapter::getArrayItems()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
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