Passed
Pull Request — master (#203)
by
unknown
02:08
created

CheckableItem::getStyle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace PhpSchool\CliMenu\MenuItem;
4
5
use PhpSchool\CliMenu\CliMenu;
6
use PhpSchool\CliMenu\Style;
7
8
class CheckableItem implements MenuItemInterface, ToggableItemInterface, CheckableInterface
9
{
10
    use ToggableTrait;
11
12
    public function __construct(
13
        string $text,
14
        callable $selectAction,
15
        bool $showItemExtra = false,
16
        bool $disabled = false
17
    ) {
18
        $this->text          = $text;
19
        $this->selectAction  = $selectAction;
20
        $this->showItemExtra = $showItemExtra;
21
        $this->disabled      = $disabled;
22
23
        $this->style = new Style\CheckableStyle();
24
    }
25
26
    public function getStyle() : Style\ItemStyleInterface
27
    {
28
        return $this->style;
29
    }
30
31
    /**
32
     * @param Style\CheckableStyle|Style\ItemStyleInterface $style
33
     * @return $this
34
     */
35
    public function setStyle(Style\ItemStyleInterface $style) : self
36
    {
37
        $this->style = $style;
38
39
        return $this;
40
    }
41
42
    /**
43
     * Execute the items callable if required
44
     */
45
    public function getSelectAction() : ?callable
46
    {
47
        return function (CliMenu $cliMenu) {
48
            $this->toggle();
49
            $cliMenu->redraw();
50
51
            return ($this->selectAction)($cliMenu);
52
        };
53
    }
54
}
55