Skip to content

Commit 6270594

Browse files
authored
Merge pull request #79 from php-school/upgrade-php-7.1
Drop PHP 7.0 and 5.x support
2 parents 5b8c472 + cf8be6a commit 6270594

39 files changed

+393
-1042
lines changed

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
language: php
22

33
php:
4-
- 5.6
5-
- 7.0
64
- 7.1
75
- 7.2
8-
- hhvm
96

107
install:
118
- composer self-update
@@ -16,8 +13,8 @@ before_script:
1613

1714
script:
1815
- ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml
19-
- ./vendor/bin/phpcs --standard=PSR2 ./src/
20-
- ./vendor/bin/phpcs --standard=PSR2 ./test/
16+
- composer cs
17+
- composer static
2118

2219
after_script:
2320
- bash <(curl -s https://codecov.io/bash)

composer.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
}
1515
],
1616
"require-dev": {
17-
"phpunit/phpunit": "~5.0",
18-
"squizlabs/php_codesniffer": "~2.0"
17+
"phpunit/phpunit": "^7.1",
18+
"squizlabs/php_codesniffer": "^3.2",
19+
"phpstan/phpstan": "^0.9.2"
1920
},
2021
"require": {
21-
"php" : ">=5.6",
22+
"php" : ">=7.1",
2223
"beberlei/assert": "^2.4",
2324
"ext-posix": "*"
2425
},
@@ -34,6 +35,9 @@
3435
"cs" : [
3536
"phpcs src --standard=PSR2",
3637
"phpcs test --standard=PSR2"
38+
],
39+
"static" : [
40+
"phpstan analyse src --level=7"
3741
]
3842
}
3943
}

src/Action/ExitAction.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@
55
use PhpSchool\CliMenu\CliMenu;
66

77
/**
8-
* Class ExitAction
9-
* @package PhpSchool\CliMenu\Action
108
* @author Aydin Hassan <[email protected]>
119
*/
1210
class ExitAction
1311
{
14-
/**
15-
* @param CliMenu $menu
16-
*/
17-
public function __invoke(CliMenu $menu)
12+
public function __invoke(CliMenu $menu) : void
1813
{
1914
$menu->close();
2015
}

src/Action/GoBackAction.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@
55
use PhpSchool\CliMenu\CliMenu;
66

77
/**
8-
* Class GoBackAction
9-
* @package PhpSchool\CliMenu\Action
108
* @author Aydin Hassan <[email protected]>
119
*/
1210
class GoBackAction
1311
{
14-
/**
15-
* @param CliMenu $menu
16-
*/
17-
public function __invoke(CliMenu $menu)
12+
public function __invoke(CliMenu $menu) : void
1813
{
1914
if ($parent = $menu->getParent()) {
2015
$menu->close();

src/CliMenu.php

Lines changed: 31 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
use PhpSchool\CliMenu\Util\StringUtil as s;
1616

1717
/**
18-
* Class CliMenu
19-
*
20-
* @package PhpSchool\CliMenu
2118
* @author Michael Woodward <[email protected]>
2219
*/
2320
class CliMenu
@@ -33,7 +30,7 @@ class CliMenu
3330
protected $style;
3431

3532
/**
36-
* @var string
33+
* @var ?string
3734
*/
3835
protected $title;
3936

@@ -58,20 +55,12 @@ class CliMenu
5855
protected $parent;
5956

6057
/**
61-
* @var Frame|null
58+
* @var Frame
6259
*/
6360
private $currentFrame;
6461

65-
/**
66-
* @param string $title
67-
* @param array $items
68-
* @param TerminalInterface|null $terminal
69-
* @param MenuStyle|null $style
70-
*
71-
* @throws InvalidTerminalException
72-
*/
7362
public function __construct(
74-
$title,
63+
?string $title,
7564
array $items,
7665
TerminalInterface $terminal = null,
7766
MenuStyle $style = null
@@ -89,7 +78,7 @@ public function __construct(
8978
*
9079
* @throws InvalidTerminalException
9180
*/
92-
protected function configureTerminal()
81+
protected function configureTerminal() : void
9382
{
9483
$this->assertTerminalIsValidTTY();
9584

@@ -103,15 +92,15 @@ protected function configureTerminal()
10392
*
10493
* @throws InvalidTerminalException
10594
*/
106-
protected function tearDownTerminal()
95+
protected function tearDownTerminal() : void
10796
{
10897
$this->assertTerminalIsValidTTY();
10998

11099
$this->terminal->setCanonicalMode(false);
111100
$this->terminal->enableCursor();
112101
}
113102

114-
private function assertTerminalIsValidTTY()
103+
private function assertTerminalIsValidTTY() : void
115104
{
116105
if (!$this->terminal->isTTY()) {
117106
throw new InvalidTerminalException(
@@ -120,44 +109,30 @@ private function assertTerminalIsValidTTY()
120109
}
121110
}
122111

123-
/**
124-
* @param CliMenu $parent
125-
*/
126-
public function setParent(CliMenu $parent)
112+
public function setParent(CliMenu $parent) : void
127113
{
128114
$this->parent = $parent;
129115
}
130116

131-
/**
132-
* @return CliMenu|null
133-
*/
134-
public function getParent()
117+
public function getParent() : ?CliMenu
135118
{
136119
return $this->parent;
137120
}
138121

139-
/**
140-
* @return TerminalInterface
141-
*/
142-
public function getTerminal()
122+
public function getTerminal() : TerminalInterface
143123
{
144124
return $this->terminal;
145125
}
146126

147-
/**
148-
* @return bool
149-
*/
150-
public function isOpen()
127+
public function isOpen() : bool
151128
{
152129
return $this->open;
153130
}
154131

155132
/**
156-
* Add a new Item to the listing
157-
*
158-
* @param MenuItemInterface $item
133+
* Add a new Item to the menu
159134
*/
160-
public function addItem(MenuItemInterface $item)
135+
public function addItem(MenuItemInterface $item) : void
161136
{
162137
$this->items[] = $item;
163138

@@ -169,7 +144,7 @@ public function addItem(MenuItemInterface $item)
169144
/**
170145
* Set the selected pointer to the first selectable item
171146
*/
172-
private function selectFirstItem()
147+
private function selectFirstItem() : void
173148
{
174149
foreach ($this->items as $key => $item) {
175150
if ($item->canSelect()) {
@@ -182,7 +157,7 @@ private function selectFirstItem()
182157
/**
183158
* Display menu and capture input
184159
*/
185-
private function display()
160+
private function display() : void
186161
{
187162
$this->draw();
188163

@@ -202,10 +177,8 @@ private function display()
202177

203178
/**
204179
* Move the selection in a given direction, up / down
205-
*
206-
* @param $direction
207180
*/
208-
protected function moveSelection($direction)
181+
protected function moveSelection(string $direction) : void
209182
{
210183
do {
211184
$itemKeys = array_keys($this->items);
@@ -224,18 +197,15 @@ protected function moveSelection($direction)
224197
} while (!$this->getSelectedItem()->canSelect());
225198
}
226199

227-
/**
228-
* @return MenuItemInterface
229-
*/
230-
public function getSelectedItem()
200+
public function getSelectedItem() : MenuItemInterface
231201
{
232202
return $this->items[$this->selectedItem];
233203
}
234204

235205
/**
236206
* Execute the current item
237207
*/
238-
protected function executeCurrentItem()
208+
protected function executeCurrentItem() : void
239209
{
240210
$item = $this->getSelectedItem();
241211

@@ -248,7 +218,7 @@ protected function executeCurrentItem()
248218
/**
249219
* Redraw the menu
250220
*/
251-
public function redraw()
221+
public function redraw() : void
252222
{
253223
if (!$this->isOpen()) {
254224
throw new MenuNotOpenException;
@@ -260,7 +230,7 @@ public function redraw()
260230
/**
261231
* Draw the menu to STDOUT
262232
*/
263-
protected function draw()
233+
protected function draw() : void
264234
{
265235
$this->terminal->clean();
266236
$this->terminal->moveCursorToTop();
@@ -269,7 +239,7 @@ protected function draw()
269239

270240
$frame->newLine(2);
271241

272-
if (is_string($this->title)) {
242+
if ($this->title) {
273243
$frame->addRows($this->drawMenuItem(new LineBreakItem()));
274244
$frame->addRows($this->drawMenuItem(new StaticItem($this->title)));
275245
$frame->addRows($this->drawMenuItem(new LineBreakItem($this->style->getTitleSeparator())));
@@ -292,12 +262,8 @@ protected function draw()
292262

293263
/**
294264
* Draw a menu item
295-
*
296-
* @param MenuItemInterface $item
297-
* @param bool|false $selected
298-
* @return array
299265
*/
300-
protected function drawMenuItem(MenuItemInterface $item, $selected = false)
266+
protected function drawMenuItem(MenuItemInterface $item, bool $selected = false) : array
301267
{
302268
$rows = $item->getRows($this->style, $selected);
303269

@@ -326,7 +292,7 @@ protected function drawMenuItem(MenuItemInterface $item, $selected = false)
326292
/**
327293
* @throws InvalidTerminalException
328294
*/
329-
public function open()
295+
public function open() : void
330296
{
331297
if ($this->isOpen()) {
332298
return;
@@ -342,7 +308,7 @@ public function open()
342308
*
343309
* @throws InvalidTerminalException
344310
*/
345-
public function close()
311+
public function close() : void
346312
{
347313
$menu = $this;
348314

@@ -354,10 +320,7 @@ public function close()
354320
$this->tearDownTerminal();
355321
}
356322

357-
/**
358-
* @throws InvalidTerminalException
359-
*/
360-
public function closeThis()
323+
public function closeThis() : void
361324
{
362325
$this->terminal->clean();
363326
$this->terminal->moveCursorToTop();
@@ -367,17 +330,14 @@ public function closeThis()
367330
/**
368331
* @return MenuItemInterface[]
369332
*/
370-
public function getItems()
333+
public function getItems() : array
371334
{
372335
return $this->items;
373336
}
374337

375-
/**
376-
* @param MenuItemInterface $item
377-
*/
378-
public function removeItem(MenuItemInterface $item)
338+
public function removeItem(MenuItemInterface $item) : void
379339
{
380-
$key = array_search($item, $this->items);
340+
$key = array_search($item, $this->items, true);
381341

382342
if (false === $key) {
383343
throw new \InvalidArgumentException('Item does not exist in menu');
@@ -387,24 +347,17 @@ public function removeItem(MenuItemInterface $item)
387347
$this->items = array_values($this->items);
388348
}
389349

390-
/**
391-
* @return MenuStyle
392-
*/
393-
public function getStyle()
350+
public function getStyle() : MenuStyle
394351
{
395352
return $this->style;
396353
}
397354

398-
public function getCurrentFrame()
355+
public function getCurrentFrame() : Frame
399356
{
400357
return $this->currentFrame;
401358
}
402359

403-
/**
404-
* @param string $text
405-
* @return Flash
406-
*/
407-
public function flash($text)
360+
public function flash(string $text) : Flash
408361
{
409362
if (strpos($text, "\n") !== false) {
410363
throw new \InvalidArgumentException;
@@ -417,11 +370,7 @@ public function flash($text)
417370
return new Flash($this, $style, $this->terminal, $text);
418371
}
419372

420-
/**
421-
* @param string $text
422-
* @return Confirm
423-
*/
424-
public function confirm($text)
373+
public function confirm($text) : Confirm
425374
{
426375
if (strpos($text, "\n") !== false) {
427376
throw new \InvalidArgumentException;

0 commit comments

Comments
 (0)