Completed
Push — master ( beaa41...f649bf )
by Aydin
12s queued 10s
created

MenuMenuItem   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 49
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getSelectAction() 0 4 1
A getText() 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
     * Returns the sub menu
45
     */
46
    public function getSubMenu() : CliMenu
47
    {
48
        return $this->subMenu;
49
    }
50
51
    /**
52
     * Display the sub menu
53
     */
54
    public function showSubMenu(CliMenu $parentMenu) : void
55
    {
56
        $parentMenu->closeThis();
57
        $this->subMenu->open();
58
    }
59
}
60