Completed
Pull Request — master (#82)
by
unknown
01:48
created

LineBreakItem::getNumberOfRows()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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