From 72a4369951d6a5189006786d7db8531a05e39879 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 7 Nov 2017 15:34:52 +0100 Subject: [PATCH] chore(php) Update to PHP 7. --- Source/Console.php | 51 ++----------------- Source/Cursor.php | 2 +- Source/GetOption.php | 2 +- Source/Readline/Autocompleter/Path.php | 8 +-- Source/Readline/Readline.php | 4 +- Source/Tput.php | 2 +- Test/Unit/Output.php | 2 +- .../Unit/Readline/Autocompleter/Aggregate.php | 8 +-- Test/Unit/Readline/Autocompleter/Path.php | 31 +++++------ Test/Unit/Window.php | 9 ++-- 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 @@ * 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 @@ public static function advancedInteraction(bool $force = false): bool /** * Restore previous interaction options. - * - * @return void */ - public static function restoreInteraction(): void + public static function restoreInteraction() { if (null === self::$_old) { return; @@ -306,11 +271,8 @@ public static function isRedirection($pipe): bool /** * 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 @@ public static function setInput(Input $input): Input /** * Get input layer. - * - * @return \Hoa\Console\Input */ public static function getInput(): Input { @@ -334,11 +294,8 @@ public static function getInput(): Input /** * 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 @@ public static function setOutput(Output $output): Output /** * 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 @@ public static function changeColor(int $fromCode, int $toColor) * • 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 @@ public function __construct(array $options, Parser $parser) /** * 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 @@ public function __construct( $root = static::PWD; } - $this->setRoot($root); + if (null !== $root) { + $this->setRoot($root); + } if (null !== $iteratorFactory) { $this->setIteratorFactory($iteratorFactory); @@ -168,7 +170,7 @@ public function getRoot(): ?string /** * 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 @@ public function setIteratorFactory(callable $iteratorFactory): ?string /** * 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 @@ public function setLineLength(int $length): void /** * 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 @@ public function count(string $number): int /** * 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 @@ public function case_write_string(): void { $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 @@ public function case_complete_no_solution(): void $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 @@ 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 @@ public function case_complete_no_solution(): void { $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 @@ public function case_complete_one_solution(): void { $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 @@ public function case_complete_with_smallest_prefix(): void { $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 @@ public function case_complete_with_longer_prefix(): void { $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 @@ public function case_get_position_on_windows(): void ->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