Completed
Pull Request — master (#151)
by
unknown
02:28
created

SplitItemBuilder   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 3
cbo 2
dl 0
loc 51
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A build() 0 9 1
A setSubMenuParents() 0 6 2
A getTerminal() 0 4 1
A getMenuStyle() 0 4 1
A end() 0 4 1
A setGutter() 0 4 1
1
<?php
2
3
namespace PhpSchool\CliMenu\Builder;
4
5
use PhpSchool\CliMenu\CliMenu;
6
use PhpSchool\CliMenu\MenuItem\SplitItem;
7
use PhpSchool\CliMenu\MenuStyle;
8
use PhpSchool\Terminal\Terminal;
9
10
/**
11
 * @author Aydin Hassan <[email protected]>
12
 */
13
class SplitItemBuilder implements Builder
14
{
15
    use BuilderUtils;
16
17
    /**
18
     * @var int
19
     */
20
    private $gutter = 2;
21
22
    public function __construct(Builder $parent)
23
    {
24
        $this->parent = $parent;
0 ignored issues
show
Bug introduced by
The property parent does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
    }
26
27
    public function build() : SplitItem
28
    {
29
        $items = $this->buildSubMenus($this->menuItems);
30
        
31
        $splitItem = new SplitItem($items);
32
        $splitItem->setGutter($this->gutter);
33
34
        return $splitItem;
35
    }
36
37
    public function setSubMenuParents(CliMenu $menu) : void
38
    {
39
        foreach ($this->subMenus as $subMenu) {
40
            $subMenu->setParent($menu);
41
        }
42
    }
43
44
    public function getTerminal() : Terminal
45
    {
46
        return $this->parent->getTerminal();
47
    }
48
49
    public function getMenuStyle() : MenuStyle
50
    {
51
        return $this->parent->getMenuStyle();
52
    }
53
54
    public function end() : CliMenuBuilder
55
    {
56
        return $this->parent;
57
    }
58
59
    public function setGutter(int $gutter) : SplitItemBuilder
60
    {
61
        $this->gutter = $gutter;
62
    }
63
}
64