Completed
Pull Request — master (#82)
by
unknown
05:12
created

StaticItem::hideItemExtra()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace PhpSchool\CliMenu\MenuItem;
4
5
use Assert\Assertion;
6
use PhpSchool\CliMenu\MenuStyle;
7
use PhpSchool\CliMenu\Util\StringUtil;
8
9
/**
10
 * @author Michael Woodward <[email protected]>
11
 */
12
class StaticItem implements MenuItemInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    private $text;
18
19
    /**
20
     * @var int
21
     */
22
    private $numberOfRows = 0;
23
24
    /**
25
     * @var int
26
     */
27
    private $startRowNumber = 0;
28
29
    public function __construct(string $text)
30
    {
31
        $this->text = $text;
32
    }
33
34
    /**
35
     * Returns the number of terminal rows the item takes
36
     */
37
    public function getNumberOfRows() : int
38
    {
39
        return $this->numberOfRows;
40
    }
41
42
    /**
43
     * Sets the row number the item starts at in the frame
44
     */
45
    public function setStartRowNumber(int $rowNumber) : void
46
    {
47
        $this->startRowNumber = $rowNumber;
48
    }
49
50
    /**
51
     * Returns the row number the item starts at in the frame
52
     */
53
    public function getStartRowNumber() : int
54
    {
55
        return $this->startRowNumber;
56
    }
57
58
    /**
59
     * The output text for the item
60
     */
61
    public function getRows(MenuStyle $style, bool $selected = false) : array
62
    {
63
        $rows = explode("\n", StringUtil::wordwrap($this->text, $style->getContentWidth()));
64
65
        $this->numberOfRows = count($rows);
66
67
        return $rows;
68
    }
69
70
    /**
71
     * Can the item be selected
72
     */
73
    public function canSelect() : bool
74
    {
75
        return false;
76
    }
77
78
    /**
79
     * Execute the items callable if required
80
     */
81
    public function getSelectAction() : ?callable
82
    {
83
        return null;
84
    }
85
86
    /**
87
     * Return the raw string of text
88
     */
89
    public function getText() : string
90
    {
91
        return $this->text;
92
    }
93
94
    /**
95
     * Whether or not the menu item is showing the menustyle extra value
96
     */
97
    public function showsItemExtra() : bool
98
    {
99
        return false;
100
    }
101
102
    /**
103
     * Enable showing item extra
104
     */
105
    public function showItemExtra() : void
106
    {
107
        //noop
108
    }
109
110
    /**
111
     * Disable showing item extra
112
     */
113
    public function hideItemExtra() : void
114
    {
115
        //noop
116
    }
117
}
118