Completed
Push — master ( 370309...3a15aa )
by Ben
03:14
created

BuildArray   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 21
ccs 9
cts 9
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B fromCollection() 0 18 5
1
<?php
2
3
namespace Thinktomorrow\Vine\Branch;
4
5
class BuildArray
6
{
7 3
    public static function fromCollection(BranchCollection $collection = null,array $mapping = [])
8
    {
9 3
        $array = [];
10
11 3
        if(empty($collection)) return $array;
12
13 3
        foreach($collection as $branch)
14
        {
15 3
            $children = $branch->hasBranches() ? self::fromCollection($branch->branches,$mapping) : null;
16 3
17
            $record = ['id' => $branch->key,'slug' => $branch->value,'name' => $branch->label];
18 3
            if($children) $record['children'] = $children;
19 2
20
            $array[] = $record;
21 3
        }
22
23
        return $array;
24
    }
25
}
26