aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2017-11-07 15:34:52 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2017-11-07 15:34:52 +0100
commit72a4369951d6a5189006786d7db8531a05e39879 (patch)
tree12098e9528fc5a2ec5e182a665fd26bb7d1835ea
parent30e32eea0c5482f83cc3127c63069fe1445a179c (diff)
downloadConsole-72a4369951d6a5189006786d7db8531a05e39879.zip
Console-72a4369951d6a5189006786d7db8531a05e39879.tar.gz
Console-72a4369951d6a5189006786d7db8531a05e39879.tar.bz2
chore(php) Update to PHP 7.
-rw-r--r--Source/Console.php51
-rw-r--r--Source/Cursor.php2
-rw-r--r--Source/GetOption.php2
-rw-r--r--Source/Readline/Autocompleter/Path.php8
-rw-r--r--Source/Readline/Readline.php4
-rw-r--r--Source/Tput.php2
-rw-r--r--Test/Unit/Output.php2
-rw-r--r--Test/Unit/Readline/Autocompleter/Aggregate.php8
-rw-r--r--Test/Unit/Readline/Autocompleter/Path.php31
-rw-r--r--Test/Unit/Window.php9
10 files changed, 37 insertions, 82 deletions
diff --git a/Source/Console.php b/Source/Console.php
index b9fdec5..9f37ffd 100644
--- a/Source/Console.php
+++ b/Source/Console.php
@@ -44,106 +44,76 @@ use Hoa\Consistency;
* Class \Hoa\Console.
*
* A set of utils and helpers about the console.
- *
- * @license New BSD License
*/
class Console
{
/**
* Pipe mode: FIFO.
- *
- * @var int
*/
public const IS_FIFO = 0;
/**
* Pipe mode: character.
- *
- * @var int
*/
public const IS_CHARACTER = 1;
/**
* Pipe mode: directory.
- *
- * @var int
*/
public const IS_DIRECTORY = 2;
/**
* Pipe mode: block.
- *
- * @var int
*/
public const IS_BLOCK = 3;
/**
* Pipe mode: regular.
- *
- * @var int
*/
public const IS_REGULAR = 4;
/**
* Pipe mode: link.
- *
- * @var int
*/
public const IS_LINK = 5;
/**
* Pipe mode: socket.
- *
- * @var int
*/
public const IS_SOCKET = 6;
/**
* Pipe mode: whiteout.
- *
- * @var int
*/
public const IS_WHITEOUT = 7;
/**
* Advanced interaction is on.
- *
- * @var bool
*/
private static $_advanced = null;
/**
* Previous STTY configuration.
- *
- * @var string
*/
private static $_old = null;
/**
* Mode.
- *
- * @var array
*/
protected static $_mode = [];
/**
* Input.
- *
- * @var \Hoa\Console\Input
*/
protected static $_input = null;
/**
* Output.
- *
- * @var \Hoa\Console\Output
*/
protected static $_output = null;
/**
* Tput.
- *
- * @var \Hoa\Console\Tput
*/
protected static $_tput = null;
@@ -151,9 +121,6 @@ class Console
/**
* Prepare the environment for advanced interactions.
- *
- * @param bool $force Force it if STDIN is not direct.
- * @return bool
*/
public static function advancedInteraction(bool $force = false): bool
{
@@ -179,10 +146,8 @@ class Console
/**
* Restore previous interaction options.
- *
- * @return void
*/
- public static function restoreInteraction(): void
+ public static function restoreInteraction()
{
if (null === self::$_old) {
return;
@@ -306,11 +271,8 @@ class Console
/**
* Set input layer.
- *
- * @param \Hoa\Console\Input $input Input.
- * @return \Hoa\Console\Input
*/
- public static function setInput(Input $input): Input
+ public static function setInput(Input $input): ?Input
{
$old = static::$_input;
static::$_input = $input;
@@ -320,8 +282,6 @@ class Console
/**
* Get input layer.
- *
- * @return \Hoa\Console\Input
*/
public static function getInput(): Input
{
@@ -334,11 +294,8 @@ class Console
/**
* Set output layer.
- *
- * @param \Hoa\Console\Output $output Output.
- * @return \Hoa\Console\Output
*/
- public static function setOutput(Output $output): Output
+ public static function setOutput(Output $output): ?Output
{
$old = static::$_output;
static::$_output = $output;
@@ -348,8 +305,6 @@ class Console
/**
* Get output layer.
- *
- * @return \Hoa\Console\Output
*/
public static function getOutput(): Output
{
diff --git a/Source/Cursor.php b/Source/Cursor.php
index 5b50b15..b44f187 100644
--- a/Source/Cursor.php
+++ b/Source/Cursor.php
@@ -640,7 +640,7 @@ class Cursor
* • u, underline, _: underline;
* • v, vertical, |: vertical.
*/
- public static function setStyle(int $style, bool $blink = true)
+ public static function setStyle(string $style, bool $blink = true)
{
if (OS_WIN) {
return;
diff --git a/Source/GetOption.php b/Source/GetOption.php
index ee2aee3..e530a84 100644
--- a/Source/GetOption.php
+++ b/Source/GetOption.php
@@ -208,7 +208,7 @@ class GetOption
/**
* Get option from the pipette.
*/
- public function getOption(?string &$optionValue, string $short = null)
+ public function getOption(&$optionValue, string $short = null)
{
static $first = true;
diff --git a/Source/Readline/Autocompleter/Path.php b/Source/Readline/Autocompleter/Path.php
index b340b93..791a3f2 100644
--- a/Source/Readline/Autocompleter/Path.php
+++ b/Source/Readline/Autocompleter/Path.php
@@ -73,7 +73,9 @@ class Path implements Autocompleter
$root = static::PWD;
}
- $this->setRoot($root);
+ if (null !== $root) {
+ $this->setRoot($root);
+ }
if (null !== $iteratorFactory) {
$this->setIteratorFactory($iteratorFactory);
@@ -168,7 +170,7 @@ class Path implements Autocompleter
/**
* Set iterator factory (a finder).
*/
- public function setIteratorFactory(callable $iteratorFactory): ?string
+ public function setIteratorFactory(callable $iteratorFactory): ?callable
{
$old = $this->_iteratorFactory;
$this->_iteratorFactory = $iteratorFactory;
@@ -179,7 +181,7 @@ class Path implements Autocompleter
/**
* Get iterator factory.
*/
- public function getIteratorFactory(): callable
+ public function getIteratorFactory(): ?callable
{
return $this->_iteratorFactory;
}
diff --git a/Source/Readline/Readline.php b/Source/Readline/Readline.php
index 679f6d8..0f37ab7 100644
--- a/Source/Readline/Readline.php
+++ b/Source/Readline/Readline.php
@@ -482,11 +482,9 @@ class Readline
/**
* Set buffer. Not for user.
*/
- public function setBuffer(string $buffer): ?string
+ public function setBuffer(string $buffer): void
{
$this->_buffer = $buffer;
-
- return;
}
/**
diff --git a/Source/Tput.php b/Source/Tput.php
index defe2c4..634aa35 100644
--- a/Source/Tput.php
+++ b/Source/Tput.php
@@ -740,7 +740,7 @@ class Tput
/**
* Get a string value.
*/
- public function get(string $string): int
+ public function get(string $string): ?string
{
if (!isset($this->_informations['strings'][$string])) {
return null;
diff --git a/Test/Unit/Output.php b/Test/Unit/Output.php
index 2d779ed..9cb0ac9 100644
--- a/Test/Unit/Output.php
+++ b/Test/Unit/Output.php
@@ -73,7 +73,7 @@ class Output extends Test\Unit\Suite
{
$this
->given($output = new SUT())
- ->when($output->writeString(123))
+ ->when($output->writeString('123'))
->then
->output
->isIdenticalTo('123');
diff --git a/Test/Unit/Readline/Autocompleter/Aggregate.php b/Test/Unit/Readline/Autocompleter/Aggregate.php
index 8edd46b..5c5cf58 100644
--- a/Test/Unit/Readline/Autocompleter/Aggregate.php
+++ b/Test/Unit/Readline/Autocompleter/Aggregate.php
@@ -87,14 +87,10 @@ class Aggregate extends Test\Unit\Suite
$this
->given(
$autocompleterA = new \Mock\Hoa\Console\Readline\Autocompleter\Autocompleter(),
- $autocompleterA->getWordDefinition = function () {
- return 'aaa';
- },
+ $this->calling($autocompleterA)->getWordDefinition = 'aaa',
$autocompleterB = new \Mock\Hoa\Console\Readline\Autocompleter\Autocompleter(),
- $autocompleterB->getWordDefinition = function () {
- return 'bbb';
- },
+ $this->calling($autocompleterB)->getWordDefinition = 'bbb',
$autocompleter = new SUT([$autocompleterA, $autocompleterB]),
$prefix = 'ccc'
diff --git a/Test/Unit/Readline/Autocompleter/Path.php b/Test/Unit/Readline/Autocompleter/Path.php
index 27546f7..e04f0ba 100644
--- a/Test/Unit/Readline/Autocompleter/Path.php
+++ b/Test/Unit/Readline/Autocompleter/Path.php
@@ -39,6 +39,7 @@ declare(strict_types=1);
namespace Hoa\Console\Test\Unit\Readline\Autocompleter;
use Hoa\Console\Readline\Autocompleter\Path as SUT;
+use Hoa\Protocol;
use Hoa\Test;
/**
@@ -83,9 +84,9 @@ class Path extends Test\Unit\Suite
{
$this
->given(
- resolve('hoa://Test/Vfs/Root?type=directory'),
- resolve('hoa://Test/Vfs/Root/Foo?type=file'),
- resolve('hoa://Test/Vfs/Root/Bar?type=file'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root?type=directory'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root/Foo?type=file'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root/Bar?type=file'),
$autocompleter = new SUT('hoa://Test/Vfs/Root'),
$prefix = 'Q'
@@ -102,9 +103,9 @@ class Path extends Test\Unit\Suite
{
$this
->given(
- resolve('hoa://Test/Vfs/Root?type=directory'),
- resolve('hoa://Test/Vfs/Root/Foo?type=file'),
- resolve('hoa://Test/Vfs/Root/Bar?type=file'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root?type=directory'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root/Foo?type=file'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root/Bar?type=file'),
$autocompleter = new SUT('hoa://Test/Vfs/Root'),
$prefix = 'F'
@@ -121,11 +122,11 @@ class Path extends Test\Unit\Suite
{
$this
->given(
- resolve('hoa://Test/Vfs/Root?type=directory'),
- resolve('hoa://Test/Vfs/Root/Foo?type=file'),
- resolve('hoa://Test/Vfs/Root/Bar?type=file'),
- resolve('hoa://Test/Vfs/Root/Baz?type=file'),
- resolve('hoa://Test/Vfs/Root/Qux?type=file'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root?type=directory'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root/Foo?type=file'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root/Bar?type=file'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root/Baz?type=file'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root/Qux?type=file'),
$autocompleter = new SUT('hoa://Test/Vfs/Root'),
$prefix = 'B'
@@ -142,10 +143,10 @@ class Path extends Test\Unit\Suite
{
$this
->given(
- resolve('hoa://Test/Vfs/Root?type=directory'),
- resolve('hoa://Test/Vfs/Root/Bara?type=file'),
- resolve('hoa://Test/Vfs/Root/Barb?type=file'),
- resolve('hoa://Test/Vfs/Root/Baza?type=file'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root?type=directory'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root/Bara?type=file'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root/Barb?type=file'),
+ Protocol\Protocol::getInstance()->resolve('hoa://Test/Vfs/Root/Baza?type=file'),
$autocompleter = new SUT('hoa://Test/Vfs/Root'),
$prefix = 'Bar'
diff --git a/Test/Unit/Window.php b/Test/Unit/Window.php
index 1652339..f314927 100644
--- a/Test/Unit/Window.php
+++ b/Test/Unit/Window.php
@@ -137,10 +137,13 @@ class Window extends Test\Unit\Suite
->given($this->constant->OS_WIN = true)
->when($result = SUT::getPosition())
->then
- ->variable($result)
- ->isNull()
->output
- ->isEmpty();
+ ->isEmpty()
+ ->array($result)
+ ->isEqualTo([
+ 'x' => 0,
+ 'y' => 0
+ ]);
}
public function case_scroll_u(): void