3232 */
3333class CliMenu
3434{
35- /**
36- * @var Terminal
37- */
38- protected $ terminal ;
35+ protected Terminal $ terminal ;
3936
40- /**
41- * @var MenuStyle
42- */
43- protected $ style ;
37+ protected MenuStyle $ style ;
4438
45- /**
46- * @var Locator
47- */
48- private $ itemStyleLocator ;
39+ private Locator $ itemStyleLocator ;
4940
50- /**
51- * @var ?string
52- */
53- protected $ title ;
41+ protected string |null $ title ;
5442
5543 /**
56- * @var MenuItemInterface[]
44+ * @var array<int, MenuItemInterface>
5745 */
58- protected $ items = [];
46+ protected array $ items = [];
5947
60- /**
61- * @var int|null
62- */
63- protected $ selectedItem ;
48+ protected int |null $ selectedItem = null ;
6449
65- /**
66- * @var bool
67- */
68- protected $ open = false ;
50+ protected bool $ open = false ;
6951
70- /**
71- * @var CliMenu|null
72- */
73- protected $ parent ;
52+ protected CliMenu |null $ parent ;
7453
7554 /**
76- * @var array
55+ * @var array<string, InputCharacter::*>
7756 */
78- protected $ defaultControlMappings = [
57+ protected array $ defaultControlMappings = [
7958 '^P ' => InputCharacter::UP ,
8059 'k ' => InputCharacter::UP ,
8160 '^K ' => InputCharacter::DOWN ,
@@ -87,15 +66,15 @@ class CliMenu
8766 ];
8867
8968 /**
90- * @var array
69+ * @var array<string, callable>
9170 */
92- protected $ customControlMappings = [];
71+ protected array $ customControlMappings = [];
72+
73+ private Frame $ currentFrame ;
9374
9475 /**
95- * @var Frame
76+ * @param list<MenuItemInterface> $items
9677 */
97- private $ currentFrame ;
98-
9978 public function __construct (
10079 ?string $ title ,
10180 array $ items ,
@@ -185,6 +164,8 @@ public function addItem(MenuItemInterface $item) : void
185164
186165 /**
187166 * Add multiple Items to the menu
167+ *
168+ * @param list<MenuItemInterface> $items
188169 */
189170 public function addItems (array $ items ) : void
190171 {
@@ -197,6 +178,8 @@ public function addItems(array $items) : void
197178
198179 /**
199180 * Set Items of the menu
181+ *
182+ * @param list<MenuItemInterface> $items
200183 */
201184 public function setItems (array $ items ) : void
202185 {
@@ -231,6 +214,9 @@ public function disableDefaultControlMappings() : void
231214
232215 /**
233216 * Set default control mappings
217+ *
218+ * @param array<string, InputCharacter::*> $defaultControlMappings
219+ *
234220 */
235221 public function setDefaultControlMappings (array $ defaultControlMappings ) : void
236222 {
@@ -249,13 +235,18 @@ public function addCustomControlMapping(string $input, callable $callable) : voi
249235 $ this ->customControlMappings [$ input ] = $ callable ;
250236 }
251237
238+ /**
239+ * @return array<string, callable>
240+ */
252241 public function getCustomControlMappings () : array
253242 {
254243 return $ this ->customControlMappings ;
255244 }
256245
257246 /**
258247 * Shorthand function to add multiple custom control mapping at once
248+ *
249+ * @param array<string, callable> $map
259250 */
260251 public function addCustomControlMappings (array $ map ) : void
261252 {
@@ -344,7 +335,7 @@ protected function moveSelectionVertically(string $direction) : void
344335 ? $ this ->selectedItem --
345336 : $ this ->selectedItem ++;
346337
347- if ($ this -> selectedItem !== null && !array_key_exists ($ this ->selectedItem , $ this ->items )) {
338+ if (!array_key_exists ($ this ->selectedItem , $ this ->items )) {
348339 $ this ->selectedItem = $ direction === 'UP '
349340 ? (int ) end ($ itemKeys )
350341 : (int ) reset ($ itemKeys );
@@ -544,6 +535,8 @@ protected function draw() : void
544535
545536 /**
546537 * Draw a menu item
538+ *
539+ * @return list<string>
547540 */
548541 protected function drawMenuItem (MenuItemInterface $ item , bool $ selected = false ) : array
549542 {
@@ -662,6 +655,9 @@ public function setStyle(MenuStyle $style) : void
662655 $ this ->style = $ style ;
663656 }
664657
658+ /**
659+ * @param class-string $styleClass
660+ */
665661 public function setItemStyle (ItemStyle $ style , string $ styleClass ) : void
666662 {
667663 $ this ->itemStyleLocator ->setStyle ($ style , $ styleClass );
0 commit comments