@@ -5,12 +5,9 @@ |
||
5 | 5 | use PhpSchool\CliMenu\Action\ExitAction; |
6 | 6 | use PhpSchool\CliMenu\Action\GoBackAction; |
7 | 7 | use PhpSchool\CliMenu\MenuItem\AsciiArtItem; |
8 | -use PhpSchool\CliMenu\MenuItem\LineBreakItem; |
|
9 | 8 | use PhpSchool\CliMenu\MenuItem\MenuItemInterface; |
10 | -use PhpSchool\CliMenu\MenuItem\MenuMenuItem; |
|
11 | 9 | use PhpSchool\CliMenu\MenuItem\SelectableItem; |
12 | 10 | use PhpSchool\CliMenu\MenuItem\SplitItem; |
13 | -use PhpSchool\CliMenu\MenuItem\StaticItem; |
|
14 | 11 | use PhpSchool\CliMenu\Terminal\TerminalFactory; |
15 | 12 | use PhpSchool\CliMenu\Util\ColourUtil; |
16 | 13 | use PhpSchool\Terminal\Terminal; |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | |
370 | 370 | private function itemsHaveExtra(array $items) : bool |
371 | 371 | { |
372 | - return !empty(array_filter($items, function (MenuItemInterface $item) { |
|
372 | + return !empty(array_filter($items, function(MenuItemInterface $item) { |
|
373 | 373 | return $item->showsItemExtra(); |
374 | 374 | })); |
375 | 375 | } |
@@ -424,12 +424,12 @@ discard block |
||
424 | 424 | throw new RuntimeException(sprintf('Menu: "%s" cannot be retrieved until menu has been built', $id)); |
425 | 425 | } |
426 | 426 | |
427 | - return $this->subMenus['submenu-placeholder-' . $id]; |
|
427 | + return $this->subMenus['submenu-placeholder-'.$id]; |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | private function buildSplitItems(array $items) : array |
431 | 431 | { |
432 | - return array_map(function ($item) { |
|
432 | + return array_map(function($item) { |
|
433 | 433 | if (!is_string($item) || 0 !== strpos($item, 'splititem-placeholder-')) { |
434 | 434 | return $item; |
435 | 435 | } |
@@ -2,9 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace PhpSchool\CliMenu\MenuItem; |
4 | 4 | |
5 | -use Assert\Assertion; |
|
6 | 5 | use PhpSchool\CliMenu\CliMenu; |
7 | -use PhpSchool\CliMenu\CliMenuBuilder; |
|
8 | 6 | use PhpSchool\CliMenu\MenuStyle; |
9 | 7 | use PhpSchool\CliMenu\Util\StringUtil; |
10 | 8 |
@@ -109,15 +109,15 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | $length = $style->getDisplaysExtra() |
112 | - ? floor($style->getContentWidth() / $numberOfItems) - (mb_strlen($style->getItemExtra()) + 2) |
|
113 | - : floor($style->getContentWidth() / $numberOfItems); |
|
112 | + ? floor($style->getContentWidth()/$numberOfItems) - (mb_strlen($style->getItemExtra()) + 2) |
|
113 | + : floor($style->getContentWidth()/$numberOfItems); |
|
114 | 114 | |
115 | 115 | $length -= $this->margin; |
116 | 116 | |
117 | - $missingLength = $style->getContentWidth() % $numberOfItems; |
|
117 | + $missingLength = $style->getContentWidth()%$numberOfItems; |
|
118 | 118 | |
119 | 119 | return $this->buildRows( |
120 | - array_map(function ($index, $item) use ($selected, $length, $style) { |
|
120 | + array_map(function($index, $item) use ($selected, $length, $style) { |
|
121 | 121 | $isSelected = $selected && $index === $this->selectedItemIndex; |
122 | 122 | $marker = $item->canSelect() |
123 | 123 | ? sprintf('%s ', $style->getMarker($isSelected)) |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | $extraPadLength = $style->getDisplaysExtra() ? 2 + mb_strlen($style->getItemExtra()) : 0; |
150 | 150 | |
151 | 151 | return array_map( |
152 | - function ($i) use ($cells, $length, $missingLength, $extraPadLength) { |
|
152 | + function($i) use ($cells, $length, $missingLength, $extraPadLength) { |
|
153 | 153 | return $this->buildRow($cells, $i, $length, $missingLength, $extraPadLength); |
154 | 154 | }, |
155 | 155 | range(0, max(array_map('count', $cells)) - 1) |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | implode( |
164 | 164 | '', |
165 | 165 | array_map( |
166 | - function ($cell) use ($index, $length, $extraPadLength) { |
|
166 | + function($cell) use ($index, $length, $extraPadLength) { |
|
167 | 167 | return $cell[$index] ?? str_repeat(' ', $length + $this->margin + $extraPadLength); |
168 | 168 | }, |
169 | 169 | $cells |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | bool $isSelected, |
181 | 181 | string $itemExtra |
182 | 182 | ) : array { |
183 | - return array_map(function ($row, $index) use ($length, $style, $isSelected, $itemExtra) { |
|
183 | + return array_map(function($row, $index) use ($length, $style, $isSelected, $itemExtra) { |
|
184 | 184 | $invertedColoursSetCode = $isSelected |
185 | 185 | ? $style->getInvertedColoursSetCode() |
186 | 186 | : ''; |
@@ -3,9 +3,9 @@ |
||
3 | 3 | use PhpSchool\CliMenu\CliMenu; |
4 | 4 | use PhpSchool\CliMenu\CliMenuBuilder; |
5 | 5 | |
6 | -require_once(__DIR__ . '/../vendor/autoload.php'); |
|
6 | +require_once(__DIR__.'/../vendor/autoload.php'); |
|
7 | 7 | |
8 | -$itemCallable = function (CliMenu $menu) { |
|
8 | +$itemCallable = function(CliMenu $menu) { |
|
9 | 9 | echo $menu->getSelectedItem()->getText(); |
10 | 10 | }; |
11 | 11 |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function addSubMenu(string $name, CliMenuBuilder $subMenuBuilder = null) : Builder |
66 | 66 | { |
67 | - $this->menuItems[] = $id = 'submenu-placeholder-' . $name; |
|
67 | + $this->menuItems[] = $id = 'submenu-placeholder-'.$name; |
|
68 | 68 | |
69 | 69 | if (null === $subMenuBuilder) { |
70 | 70 | $this->subMenuBuilders[$id] = new CliMenuBuilder($this); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | private function buildSubMenus(array $items) : array |
79 | 79 | { |
80 | - return array_map(function ($item) { |
|
80 | + return array_map(function($item) { |
|
81 | 81 | if (!is_string($item) || 0 !== strpos($item, 'submenu-placeholder-')) { |
82 | 82 | return $item; |
83 | 83 | } |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | : $this->selectedItem++; |
286 | 286 | |
287 | 287 | if (!array_key_exists($this->selectedItem, $this->items)) { |
288 | - $this->selectedItem = $direction === 'UP' |
|
288 | + $this->selectedItem = $direction === 'UP' |
|
289 | 289 | ? end($itemKeys) |
290 | 290 | : reset($itemKeys); |
291 | 291 | } |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | $frame->addRows($this->drawMenuItem(new LineBreakItem($this->style->getTitleSeparator()))); |
388 | 388 | } |
389 | 389 | |
390 | - array_map(function ($item, $index) use ($frame) { |
|
390 | + array_map(function($item, $index) use ($frame) { |
|
391 | 391 | $frame->addRows($this->drawMenuItem($item, $index === $this->selectedItem)); |
392 | 392 | }, $this->items, array_keys($this->items)); |
393 | 393 | |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | $borderColour = ''; |
439 | 439 | } |
440 | 440 | |
441 | - return array_map(function ($row) use ($invertedColoursSetCode, $invertedColoursUnsetCode, $borderColour) { |
|
441 | + return array_map(function($row) use ($invertedColoursSetCode, $invertedColoursUnsetCode, $borderColour) { |
|
442 | 442 | return sprintf( |
443 | 443 | "%s%s%s%s%s%s%s%s%s%s%s%s\n", |
444 | 444 | str_repeat(' ', $this->style->getMargin()), |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | { |
16 | 16 | return implode( |
17 | 17 | $break, |
18 | - array_map(function (string $line) use ($width, $break) { |
|
18 | + array_map(function(string $line) use ($width, $break) { |
|
19 | 19 | $line = rtrim($line); |
20 | 20 | if (mb_strlen($line) <= $width) { |
21 | 21 | return $line; |
@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | $line = ''; |
26 | 26 | $actual = ''; |
27 | 27 | foreach ($words as $word) { |
28 | - if (mb_strlen($actual . $word) <= $width) { |
|
29 | - $actual .= $word . ' '; |
|
28 | + if (mb_strlen($actual.$word) <= $width) { |
|
29 | + $actual .= $word.' '; |
|
30 | 30 | } else { |
31 | 31 | if ($actual !== '') { |
32 | - $line .= rtrim($actual) . $break; |
|
32 | + $line .= rtrim($actual).$break; |
|
33 | 33 | } |
34 | - $actual = $word . ' '; |
|
34 | + $actual = $word.' '; |
|
35 | 35 | } |
36 | 36 | } |
37 | - return $line . trim($actual); |
|
37 | + return $line.trim($actual); |
|
38 | 38 | }, explode($break, $string)) |
39 | 39 | ); |
40 | 40 | } |