Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Commit

Permalink
chore(php) Update to PHP 7.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Nov 7, 2017
1 parent 30e32ee commit 72a4369
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 82 deletions.
51 changes: 3 additions & 48 deletions Source/Console.php
Expand Up @@ -44,116 +44,83 @@
* 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;



/**
* 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
{
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -320,8 +282,6 @@ public static function setInput(Input $input): Input

/**
* Get input layer.
*
* @return \Hoa\Console\Input
*/
public static function getInput(): Input
{
Expand All @@ -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;
Expand All @@ -348,8 +305,6 @@ public static function setOutput(Output $output): Output

/**
* Get output layer.
*
* @return \Hoa\Console\Output
*/
public static function getOutput(): Output
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Cursor.php
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/GetOption.php
Expand Up @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions Source/Readline/Autocompleter/Path.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -179,7 +181,7 @@ public function setIteratorFactory(callable $iteratorFactory): ?string
/**
* Get iterator factory.
*/
public function getIteratorFactory(): callable
public function getIteratorFactory(): ?callable
{
return $this->_iteratorFactory;
}
Expand Down
4 changes: 1 addition & 3 deletions Source/Readline/Readline.php
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Source/Tput.php
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Test/Unit/Output.php
Expand Up @@ -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');
Expand Down
8 changes: 2 additions & 6 deletions Test/Unit/Readline/Autocompleter/Aggregate.php
Expand Up @@ -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'
Expand Down
31 changes: 16 additions & 15 deletions Test/Unit/Readline/Autocompleter/Path.php
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand Down
9 changes: 6 additions & 3 deletions Test/Unit/Window.php
Expand Up @@ -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
Expand Down

0 comments on commit 72a4369

Please sign in to comment.