Completed
Push — master ( 33d412...b764b5 )
by Ben
02:26
created

Branch   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 34
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A hasBranches() 0 4 1
A push() 0 6 1
A __get() 0 6 2
1
<?php
2
3
namespace Thinktomorrow\Vine\Branch;
4
5
use Thinktomorrow\Vine\VineException;
6
7
/**
8
 * Class Branch
9
 *
10
 * @property string $key
11
 * @property string $value
12
 * @property string $label
13
 * @property array $branches
14
 */
15
class Branch
16
{
17
    private $key;
18
    private $value;
19
    private $label;
20
    private $branches;
21
22 42
    public function __construct($key, $value, $label, BranchCollection $branches = null)
23
    {
24 42
        $this->key = $key;
25 42
        $this->value = $value;
26 42
        $this->label = $label;
27 42
        $this->branches = $branches?: new BranchCollection();
28 42
    }
29
30 12
    public function hasBranches()
31
    {
32 12
        return ($this->branches->hasBranches());
33
    }
34
35 9
    public function push(Branch $branch)
36
    {
37 9
        $this->branches[] = $branch;
38
39 9
        return $this;
40
    }
41
42 42
    public function __get($key)
43
    {
44 42
        if(isset($this->$key)) return $this->$key;
45
46 3
        throw VineException::unknownBranchAttribute($key);
47
    }
48
}
49