Skip to content

Drop PHP 7.0 and 5.x support #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm

install:
- composer self-update
Expand All @@ -16,8 +13,8 @@ before_script:

script:
- ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml
- ./vendor/bin/phpcs --standard=PSR2 ./src/
- ./vendor/bin/phpcs --standard=PSR2 ./test/
- composer cs
- composer static

after_script:
- bash <(curl -s https://codecov.io/bash)
Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
}
],
"require-dev": {
"phpunit/phpunit": "~5.0",
"squizlabs/php_codesniffer": "~2.0"
"phpunit/phpunit": "^7.1",
"squizlabs/php_codesniffer": "^3.2",
"phpstan/phpstan": "^0.9.2"
},
"require": {
"php" : ">=5.6",
"php" : ">=7.1",
"beberlei/assert": "^2.4",
"ext-posix": "*"
},
Expand All @@ -34,6 +35,9 @@
"cs" : [
"phpcs src --standard=PSR2",
"phpcs test --standard=PSR2"
],
"static" : [
"phpstan analyse src --level=7"
]
}
}
7 changes: 1 addition & 6 deletions src/Action/ExitAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
use PhpSchool\CliMenu\CliMenu;

/**
* Class ExitAction
* @package PhpSchool\CliMenu\Action
* @author Aydin Hassan <[email protected]>
*/
class ExitAction
{
/**
* @param CliMenu $menu
*/
public function __invoke(CliMenu $menu)
public function __invoke(CliMenu $menu) : void
{
$menu->close();
}
Expand Down
7 changes: 1 addition & 6 deletions src/Action/GoBackAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
use PhpSchool\CliMenu\CliMenu;

/**
* Class GoBackAction
* @package PhpSchool\CliMenu\Action
* @author Aydin Hassan <[email protected]>
*/
class GoBackAction
{
/**
* @param CliMenu $menu
*/
public function __invoke(CliMenu $menu)
public function __invoke(CliMenu $menu) : void
{
if ($parent = $menu->getParent()) {
$menu->close();
Expand Down
113 changes: 31 additions & 82 deletions src/CliMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
use PhpSchool\CliMenu\Util\StringUtil as s;

/**
* Class CliMenu
*
* @package PhpSchool\CliMenu
* @author Michael Woodward <[email protected]>
*/
class CliMenu
Expand All @@ -33,7 +30,7 @@ class CliMenu
protected $style;

/**
* @var string
* @var ?string
*/
protected $title;

Expand All @@ -58,20 +55,12 @@ class CliMenu
protected $parent;

/**
* @var Frame|null
* @var Frame
*/
private $currentFrame;

/**
* @param string $title
* @param array $items
* @param TerminalInterface|null $terminal
* @param MenuStyle|null $style
*
* @throws InvalidTerminalException
*/
public function __construct(
$title,
?string $title,
array $items,
TerminalInterface $terminal = null,
MenuStyle $style = null
Expand All @@ -89,7 +78,7 @@ public function __construct(
*
* @throws InvalidTerminalException
*/
protected function configureTerminal()
protected function configureTerminal() : void
{
$this->assertTerminalIsValidTTY();

Expand All @@ -103,15 +92,15 @@ protected function configureTerminal()
*
* @throws InvalidTerminalException
*/
protected function tearDownTerminal()
protected function tearDownTerminal() : void
{
$this->assertTerminalIsValidTTY();

$this->terminal->setCanonicalMode(false);
$this->terminal->enableCursor();
}

private function assertTerminalIsValidTTY()
private function assertTerminalIsValidTTY() : void
{
if (!$this->terminal->isTTY()) {
throw new InvalidTerminalException(
Expand All @@ -120,44 +109,30 @@ private function assertTerminalIsValidTTY()
}
}

/**
* @param CliMenu $parent
*/
public function setParent(CliMenu $parent)
public function setParent(CliMenu $parent) : void
{
$this->parent = $parent;
}

/**
* @return CliMenu|null
*/
public function getParent()
public function getParent() : ?CliMenu
{
return $this->parent;
}

/**
* @return TerminalInterface
*/
public function getTerminal()
public function getTerminal() : TerminalInterface
{
return $this->terminal;
}

/**
* @return bool
*/
public function isOpen()
public function isOpen() : bool
{
return $this->open;
}

/**
* Add a new Item to the listing
*
* @param MenuItemInterface $item
* Add a new Item to the menu
*/
public function addItem(MenuItemInterface $item)
public function addItem(MenuItemInterface $item) : void
{
$this->items[] = $item;

Expand All @@ -169,7 +144,7 @@ public function addItem(MenuItemInterface $item)
/**
* Set the selected pointer to the first selectable item
*/
private function selectFirstItem()
private function selectFirstItem() : void
{
foreach ($this->items as $key => $item) {
if ($item->canSelect()) {
Expand All @@ -182,7 +157,7 @@ private function selectFirstItem()
/**
* Display menu and capture input
*/
private function display()
private function display() : void
{
$this->draw();

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

/**
* Move the selection in a given direction, up / down
*
* @param $direction
*/
protected function moveSelection($direction)
protected function moveSelection(string $direction) : void
{
do {
$itemKeys = array_keys($this->items);
Expand All @@ -224,18 +197,15 @@ protected function moveSelection($direction)
} while (!$this->getSelectedItem()->canSelect());
}

/**
* @return MenuItemInterface
*/
public function getSelectedItem()
public function getSelectedItem() : MenuItemInterface
{
return $this->items[$this->selectedItem];
}

/**
* Execute the current item
*/
protected function executeCurrentItem()
protected function executeCurrentItem() : void
{
$item = $this->getSelectedItem();

Expand All @@ -248,7 +218,7 @@ protected function executeCurrentItem()
/**
* Redraw the menu
*/
public function redraw()
public function redraw() : void
{
if (!$this->isOpen()) {
throw new MenuNotOpenException;
Expand All @@ -260,7 +230,7 @@ public function redraw()
/**
* Draw the menu to STDOUT
*/
protected function draw()
protected function draw() : void
{
$this->terminal->clean();
$this->terminal->moveCursorToTop();
Expand All @@ -269,7 +239,7 @@ protected function draw()

$frame->newLine(2);

if (is_string($this->title)) {
if ($this->title) {
$frame->addRows($this->drawMenuItem(new LineBreakItem()));
$frame->addRows($this->drawMenuItem(new StaticItem($this->title)));
$frame->addRows($this->drawMenuItem(new LineBreakItem($this->style->getTitleSeparator())));
Expand All @@ -292,12 +262,8 @@ protected function draw()

/**
* Draw a menu item
*
* @param MenuItemInterface $item
* @param bool|false $selected
* @return array
*/
protected function drawMenuItem(MenuItemInterface $item, $selected = false)
protected function drawMenuItem(MenuItemInterface $item, bool $selected = false) : array
{
$rows = $item->getRows($this->style, $selected);

Expand Down Expand Up @@ -326,7 +292,7 @@ protected function drawMenuItem(MenuItemInterface $item, $selected = false)
/**
* @throws InvalidTerminalException
*/
public function open()
public function open() : void
{
if ($this->isOpen()) {
return;
Expand All @@ -342,7 +308,7 @@ public function open()
*
* @throws InvalidTerminalException
*/
public function close()
public function close() : void
{
$menu = $this;

Expand All @@ -354,10 +320,7 @@ public function close()
$this->tearDownTerminal();
}

/**
* @throws InvalidTerminalException
*/
public function closeThis()
public function closeThis() : void
{
$this->terminal->clean();
$this->terminal->moveCursorToTop();
Expand All @@ -367,17 +330,14 @@ public function closeThis()
/**
* @return MenuItemInterface[]
*/
public function getItems()
public function getItems() : array
{
return $this->items;
}

/**
* @param MenuItemInterface $item
*/
public function removeItem(MenuItemInterface $item)
public function removeItem(MenuItemInterface $item) : void
{
$key = array_search($item, $this->items);
$key = array_search($item, $this->items, true);

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

/**
* @return MenuStyle
*/
public function getStyle()
public function getStyle() : MenuStyle
{
return $this->style;
}

public function getCurrentFrame()
public function getCurrentFrame() : Frame
{
return $this->currentFrame;
}

/**
* @param string $text
* @return Flash
*/
public function flash($text)
public function flash(string $text) : Flash
{
if (strpos($text, "\n") !== false) {
throw new \InvalidArgumentException;
Expand All @@ -417,11 +370,7 @@ public function flash($text)
return new Flash($this, $style, $this->terminal, $text);
}

/**
* @param string $text
* @return Confirm
*/
public function confirm($text)
public function confirm($text) : Confirm
{
if (strpos($text, "\n") !== false) {
throw new \InvalidArgumentException;
Expand Down
Loading