Completed
Push — master ( 306131...5909ec )
by Aydin
06:33 queued 03:57
created

MenuMenuItem   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 57
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getSelectAction() 0 4 1
A getText() 0 4 1
A setText() 0 4 1
A getSubMenu() 0 4 1
A showSubMenu() 0 5 1
1
<?php
2
3
namespace PhpSchool\CliMenu\MenuItem;
4
5
use Assert\Assertion;
6
use PhpSchool\CliMenu\CliMenu;
7
8
/**
9
 * @author Michael Woodward <[email protected]>
10
 */
11
class MenuMenuItem implements MenuItemInterface
12
{
13
    use SelectableTrait;
14
    
15
    /**
16
     * @var CliMenu
17
     */
18
    private $subMenu;
19
20
    public function __construct(string $text, CliMenu $subMenu, bool $disabled = false)
21
    {
22
        $this->text     = $text;
23
        $this->subMenu  = $subMenu;
24
        $this->disabled = $disabled;
25
    }
26
27
    /**
28
     * Execute the items callable if required
29
     */
30
    public function getSelectAction() : ?callable
31
    {
32
        return [$this, 'showSubMenu'];
33
    }
34
35
    /**
36
     * Return the raw string of text
37
     */
38
    public function getText() : string
39
    {
40
        return $this->text;
41
    }
42
43
    /**
44
     * Set the raw string of text
45
     */
46
    public function setText(string $text) : void
47
    {
48
        $this->text = $text;
49
    }
50
    
51
    /**
52
     * Returns the sub menu
53
     */
54
    public function getSubMenu() : CliMenu
55
    {
56
        return $this->subMenu;
57
    }
58
59
    /**
60
     * Display the sub menu
61
     */
62
    public function showSubMenu(CliMenu $parentMenu) : void
63
    {
64
        $parentMenu->closeThis();
65
        $this->subMenu->open();
66
    }
67
}
68