aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2017-11-07 14:57:57 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2017-11-07 14:57:57 +0100
commit30e32eea0c5482f83cc3127c63069fe1445a179c (patch)
tree56dd75093c5c85dfbd16176f784bc17f99cfedf1
parentb5cafe1bbcdbb6ea2fb8b9bf8e290bfff0fea6ec (diff)
downloadConsole-30e32eea0c5482f83cc3127c63069fe1445a179c.zip
Console-30e32eea0c5482f83cc3127c63069fe1445a179c.tar.gz
Console-30e32eea0c5482f83cc3127c63069fe1445a179c.tar.bz2
chore(php) Update to PHP 7.
-rw-r--r--Source/Chrome/Editor.php9
-rw-r--r--Source/Chrome/Exception.php2
-rw-r--r--Source/Chrome/Pager.php21
-rw-r--r--Source/Chrome/Text.php53
-rw-r--r--Source/Console.php31
-rw-r--r--Source/Cursor.php60
-rw-r--r--Source/Dispatcher/Kit.php49
-rw-r--r--Source/Exception.php2
-rw-r--r--Source/GetOption.php43
-rw-r--r--Source/Input.php38
-rw-r--r--Source/Mouse.php31
-rw-r--r--Source/Output.php49
-rw-r--r--Source/Parser.php60
-rw-r--r--Source/Processus.php26
-rw-r--r--Source/Readline/Autocompleter/Aggregate.php22
-rw-r--r--Source/Readline/Autocompleter/Autocompleter.php11
-rw-r--r--Source/Readline/Autocompleter/Path.php49
-rw-r--r--Source/Readline/Autocompleter/Word.php22
-rw-r--r--Source/Readline/Password.php6
-rw-r--r--Source/Readline/Readline.php196
-rw-r--r--Source/Tput.php4
-rw-r--r--Source/Window.php6
22 files changed, 87 insertions, 703 deletions
diff --git a/Source/Chrome/Editor.php b/Source/Chrome/Editor.php
index 49df5c4..9a6c3d3 100644
--- a/Source/Chrome/Editor.php
+++ b/Source/Chrome/Editor.php
@@ -44,20 +44,13 @@ use Hoa\Console;
* Class \Hoa\Console\Chrome\Editor.
*
* Start an editor.
- *
- * @license New BSD License
*/
class Editor
{
/**
* Open an editor.
- *
- * @param string $file File to open.
- * @param string $editor Editor to use ($_SERVER['EDITOR'] by
- * default).
- * @return string
*/
- public static function open(string $file = '', string $editor = null): string
+ public static function open(string $file = '', string $editor = null): ?string
{
if (null === $editor) {
if (isset($_SERVER['EDITOR'])) {
diff --git a/Source/Chrome/Exception.php b/Source/Chrome/Exception.php
index a81b5e5..ea9c80a 100644
--- a/Source/Chrome/Exception.php
+++ b/Source/Chrome/Exception.php
@@ -44,8 +44,6 @@ use Hoa\Console;
* Class \Hoa\Console\Chrome\Exception.
*
* Extending the \Hoa\Console\Exception class.
- *
- * @license New BSD License
*/
class Exception extends Console\Exception
{
diff --git a/Source/Chrome/Pager.php b/Source/Chrome/Pager.php
index 98f31fc..8702cfd 100644
--- a/Source/Chrome/Pager.php
+++ b/Source/Chrome/Pager.php
@@ -47,22 +47,16 @@ use Hoa\Console;
*
* ob_start('Hoa\Console\Chrome\Pager::less');
* echo file_get_contents(__FILE__);
- *
- * @license New BSD License
*/
class Pager
{
/**
* Represent LESS(1).
- *
- * @const string
*/
public const LESS = 'less';
/**
* Represent MORE(1).
- *
- * @const string
*/
public const MORE = 'more';
@@ -70,10 +64,6 @@ class Pager
/**
* Use less.
- *
- * @param string $output Output (from the output buffer).
- * @param int $mode Mode (from the output buffer).
- * @return string
*/
public static function less(string $output, int $mode): string
{
@@ -82,10 +72,6 @@ class Pager
/**
* Use more.
- *
- * @param string $output Output (from the output buffer).
- * @param int $mode Mode (from the output buffer).
- * @return string
*/
public static function more(string $output, int $mode): string
{
@@ -94,13 +80,8 @@ class Pager
/**
* Use pager set in the environment (i.e. $_ENV['PAGER']).
- *
- * @param string $output Output (from the output buffer).
- * @param int $mode Mode (from the output buffer).
- * @param string $type Type. Please, see self::LESS or self::MORE.
- * @return string
*/
- public static function pager(string $output, int $mode, string $type = null): string
+ public static function pager(string $output, int $mode, string $type = null): ?string
{
static $process = null;
diff --git a/Source/Chrome/Text.php b/Source/Chrome/Text.php
index 3ae2f28..3fad00b 100644
--- a/Source/Chrome/Text.php
+++ b/Source/Chrome/Text.php
@@ -44,29 +44,21 @@ use Hoa\Console;
* Class \Hoa\Console\Chrome\Text.
*
* This class builts the text layout.
- *
- * @license New BSD License
*/
class Text
{
/**
* Align the text to left.
- *
- * @const int
*/
public const ALIGN_LEFT = 0;
/**
* Align the text to right.
- *
- * @const int
*/
public const ALIGN_RIGHT = 1;
/**
* Align the text to center.
- *
- * @const int
*/
public const ALIGN_CENTER = 2;
@@ -75,11 +67,6 @@ class Text
/**
* Colorize a portion of a text.
* It is kind of a shortcut of \Hoa\Console\Color.
- *
- * @param string $text Text.
- * @param string $attributesBefore Style to apply.
- * @param string $attributesAfter Reset style.
- * @return string
*/
public static function colorize(
string $text,
@@ -113,23 +100,13 @@ class Text
* For example : '|: ', will set a ': ' between the first and second column,
* and nothing for the other.
*
- * @param Array $line The table represented by an array
- * (see the documentation).
- * @param int $alignement The global alignement of the text
- * in cell.
- * @param int $horizontalPadding The horizontal padding (right
- * padding).
- * @param int $verticalPadding The vertical padding.
- * @param string $separator String where each character is a
- * column separator.
- * @return string
*/
public static function columnize(
array $line,
- int $alignement = self::ALIGN_LEFT,
- int $horizontalPadding = 2,
- int $verticalPadding = 0,
- string $separator = null
+ int $alignement = self::ALIGN_LEFT,
+ float $horizontalPadding = 2,
+ float $verticalPadding = 0,
+ string $separator = null
): string {
if (empty($line)) {
return '';
@@ -269,7 +246,7 @@ class Text
}
}
- $format .= str_repeat("\n", $verticalPadding + 1);
+ $format .= str_repeat("\n", (int) round($verticalPadding + 1));
array_unshift($handle, $format);
$out .= call_user_func_array('sprintf', $handle);
@@ -280,11 +257,6 @@ class Text
/**
* Align a text according a “layer”. The layer width is given in arguments.
- *
- * @param string $text The text.
- * @param int $alignement The text alignement.
- * @param int $width The layer width.
- * @return string
*/
public static function align(
string $text,
@@ -326,9 +298,6 @@ class Text
/**
* Get the maximum line width.
- *
- * @param mixed $lines The line (or group of lines).
- * @return int
*/
protected static function getMaxLineWidth($lines): int
{
@@ -350,9 +319,6 @@ class Text
/**
* Get the maximum line number (count the new-line character).
- *
- * @param mixed $lines The line (or group of lines).
- * @return int
*/
protected static function getMaxLineNumber($lines): int
{
@@ -372,11 +338,6 @@ class Text
/**
* My own wordwrap (just force the wordwrap() $cut parameter)..
- *
- * @param string $text Text to wrap.
- * @param int $width Line width.
- * @param string $break String to make the break.
- * @return string
*/
public static function wordwrap(string $text, int $width = null, string $break = "\n"): string
{
@@ -390,10 +351,6 @@ class Text
/**
* Underline with a special string.
- *
- * @param string $text The text to underline.
- * @param string $pattern The string used to underline.
- * @return string
*/
public static function underline(string $text, string $pattern = '*'): string
{
diff --git a/Source/Console.php b/Source/Console.php
index c052229..b9fdec5 100644
--- a/Source/Console.php
+++ b/Source/Console.php
@@ -196,11 +196,8 @@ class Console
/**
* Get mode of a certain pipe.
* Inspired by sys/stat.h.
- *
- * @param resource $pipe Pipe.
- * @return int
*/
- public static function getMode(resource $pipe = STDIN): int
+ public static function getMode($pipe = STDIN): int
{
$_pipe = (int) $pipe;
@@ -272,11 +269,8 @@ class Console
* For example:
* $ php Mode.php
* In this case, self::isDirect(STDOUT) will return true.
- *
- * @param resource $pipe Pipe.
- * @return bool
*/
- public static function isDirect(resource $pipe): bool
+ public static function isDirect($pipe): bool
{
return self::IS_CHARACTER === self::getMode($pipe);
}
@@ -286,11 +280,8 @@ class Console
* For example:
* $ php Mode.php | foobar
* In this case, self::isPipe(STDOUT) will return true.
- *
- * @param resource $pipe Pipe.
- * @return bool
*/
- public static function isPipe(resource $pipe): bool
+ public static function isPipe($pipe): bool
{
return self::IS_FIFO === self::getMode($pipe);
}
@@ -300,11 +291,8 @@ class Console
* For example:
* $ php Mode.php < foobar
* In this case, self::isRedirection(STDIN) will return true.
- *
- * @param resource $pipe Pipe.
- * @return bool
*/
- public static function isRedirection(resource $pipe): bool
+ public static function isRedirection($pipe): bool
{
$mode = self::getMode($pipe);
@@ -374,11 +362,8 @@ class Console
/**
* Set tput.
- *
- * @param \Hoa\Console\Tput $tput Tput.
- * @return \Hoa\Console\Tput
*/
- public static function setTput(Tput $tput): Tput
+ public static function setTput(Tput $tput): ?Tput
{
$old = static::$_tput;
static::$_tput = $tput;
@@ -388,8 +373,6 @@ class Console
/**
* Get the current tput instance of the current process.
- *
- * @return \Hoa\Console\Tput
*/
public static function getTput(): Tput
{
@@ -402,8 +385,6 @@ class Console
/**
* Check whether we are running behind TMUX(1).
- *
- * @return bool
*/
public static function isTmuxRunning(): bool
{
@@ -419,4 +400,4 @@ Consistency::registerShutdownFunction(xcallable('Hoa\Console\Console::restoreInt
/**
* Flex entity.
*/
-Consistency::flexEntity('Hoa\Console\Console');
+Consistency::flexEntity(Console::class);
diff --git a/Source/Cursor.php b/Source/Cursor.php
index ff0c217..5b50b15 100644
--- a/Source/Cursor.php
+++ b/Source/Cursor.php
@@ -42,8 +42,6 @@ namespace Hoa\Console;
* Class \Hoa\Console\Cursor.
*
* Allow to manipulate the cursor.
- *
- * @license New BSD License
*/
class Cursor
{
@@ -59,12 +57,8 @@ class Cursor
* • l, left, ← : move to the previous column;
* • L, LEFT : move to the first column.
* Steps can be concatened by a single space if $repeat is equal to 1.
- *
- * @param string $steps Steps.
- * @param int $repeat How many times do we move?
- * @return void
*/
- public static function move(string $steps, int $repeat = 1): void
+ public static function move(string $steps, int $repeat = 1)
{
if (1 > $repeat) {
return;
@@ -156,17 +150,11 @@ class Cursor
break;
}
}
-
- return;
}
/**
* Move to the line X and the column Y.
* If null, use the current coordinate.
- *
- * @param int $x X coordinate.
- * @param int $y Y coordinate.
- * @return void
*/
public static function moveTo(int $x = null, int $y = null): void
{
@@ -189,14 +177,10 @@ class Cursor
Console::getTput()->get('cursor_address')
)
);
-
- return;
}
/**
* Get current position (x and y) of the cursor.
- *
- * @return array
*/
public static function getPosition(): array
{
@@ -246,30 +230,22 @@ class Cursor
/**
* Save current position.
- *
- * @return void
*/
public static function save(): void
{
Console::getOutput()->writeAll(
Console::getTput()->get('save_cursor')
);
-
- return;
}
/**
* Restore cursor to the last saved position.
- *
- * @return void
*/
public static function restore(): void
{
Console::getOutput()->writeAll(
Console::getTput()->get('restore_cursor')
);
-
- return;
}
/**
@@ -282,9 +258,6 @@ class Cursor
* • l, left, ← : clear from cursor to beginning of the screen;
* • line, ↔ : clear all the line and static::move(1).
* Parts can be concatenated by a single space.
- *
- * @param string $parts Parts to clean.
- * @return void
*/
public static function clear(string $parts = 'all'): void
{
@@ -336,36 +309,26 @@ class Cursor
break;
}
}
-
- return;
}
/**
* Hide the cursor.
- *
- * @return void
*/
public static function hide(): void
{
Console::getOutput()->writeAll(
Console::getTput()->get('cursor_invisible')
);
-
- return;
}
/**
* Show the cursor.
- *
- * @return void
*/
public static function show(): void
{
Console::getOutput()->writeAll(
Console::getTput()->get('cursor_visible')
);
-
- return;
}
/**
@@ -395,11 +358,8 @@ class Cursor
* • 0-256 (classic palette);
* • #hexa.
* Attributes can be concatenated by a single space.
- *
- * @param string $attributes Attributes.
- * @return void
*/
- public static function colorize(string $attributes): void
+ public static function colorize(string $attributes)
{
static $_rgbTo256 = null;
@@ -637,12 +597,8 @@ class Cursor
/**
* Change color number to a specific RGB color.
- *
- * @param int $fromCode Color number.
- * @param int $toColor RGB color.
- * @return void
*/
- public static function changeColor(int $fromCode, int $toColor): void
+ public static function changeColor(int $fromCode, int $toColor)
{
$tput = Console::getTput();
@@ -683,12 +639,8 @@ class Cursor
* • b, block, ▋: block;
* • u, underline, _: underline;
* • v, vertical, |: vertical.
- *
- * @param int $style Style.
- * @param bool $blink Whether the cursor is blink or steady.
- * @return void
*/
- public static function setStyle(int $style, bool $blink = true): void
+ public static function setStyle(int $style, bool $blink = true)
{
if (OS_WIN) {
return;
@@ -729,16 +681,12 @@ class Cursor
/**
* Make a stupid “bip”.
- *
- * @return void
*/
public static function bip(): void
{
Console::getOutput()->writeAll(
Console::getTput()->get('bell')
);
-
- return;
}
}
diff --git a/Source/Dispatcher/Kit.php b/Source/Dispatcher/Kit.php
index 3d27742..dceba43 100644
--- a/Source/Dispatcher/Kit.php
+++ b/Source/Dispatcher/Kit.php
@@ -47,29 +47,21 @@ use Hoa\View;
* Class \Hoa\Console\Dispatcher\Kit.
*
* A structure, given to action, that holds some important data.
- *
- * @license New BSD License
*/
class Kit extends Dispatcher\Kit
{
/**
* CLI parser.
- *
- * @var \Hoa\Console\Parser
*/
public $parser = null;
/**
* Options (as described in \Hoa\Console\GetOption).
- *
- * @var array
*/
protected $options = null;
/**
* Options analyzer.
- *
- * @var \Hoa\Console\GetOption
*/
protected $_options = null;
@@ -77,10 +69,6 @@ class Kit extends Dispatcher\Kit
/**
* Build a dispatcher kit.
- *
- * @param \Hoa\Router $router The router.
- * @param \Hoa\Dispatcher $dispatcher The dispatcher.
- * @param \Hoa\View\Viewable $view The view.
*/
public function __construct(
Router $router,
@@ -96,12 +84,8 @@ class Kit extends Dispatcher\Kit
/**
* Alias of \Hoa\Console\GetOption::getOptions().
- *
- * @param string &$optionValue Please, see original API.
- * @param string $short Please, see original API.
- * @return mixed
*/
- public function getOption(&$optionValue, string $short = null)
+ public function getOption(?string &$optionValue, string $short = null)
{
if (null === $this->_options && !empty($this->options)) {
$this->setOptions($this->options);
@@ -116,12 +100,8 @@ class Kit extends Dispatcher\Kit
/**
* Initialize options.
- *
- * @param array $options Options, as described in
- * \Hoa\Console\GetOption.
- * @return array
*/
- public function setOptions(array $options): array
+ public function setOptions(array $options): ?array
{
$old = $this->options;
$this->options = $options;
@@ -141,10 +121,6 @@ class Kit extends Dispatcher\Kit
/**
* It is a helper to make the usage options list.
- *
- * @param array $definitions An associative arry: short or long option
- * associated to the definition.
- * @return string
*/
public function makeUsageOptionsList(array $definitions = []): string
{
@@ -185,9 +161,6 @@ class Kit extends Dispatcher\Kit
/**
* Resolve option ambiguity by asking the user to choose amongst some
* appropriated solutions.
- *
- * @param array $solutions Solutions.
- * @return void
*/
public function resolveOptionAmbiguity(array $solutions): void
{
@@ -205,16 +178,10 @@ class Kit extends Dispatcher\Kit
$solutions['solutions'] = [$new];
$this->_options->resolveOptionAmbiguity($solutions);
-
- return;
}
/**
* Make a render of an operation.
- *
- * @param string $text The operation text.
- * @param bool $status The operation status.
- * @return void
*/
public function status(string $text, bool $status): void
{
@@ -232,17 +199,12 @@ class Kit extends Dispatcher\Kit
: '[' . Console\Chrome\Text::colorize('!!', 'foreground(white) background(red)') . ']');
Console::getOutput()->writeAll($out . "\n");
-
- return;
}
/**
* Read, edit, bind… a line from STDIN.
- *
- * @param string $prefix Prefix.
- * @return string
*/
- public function readLine(string $prefix = null): string
+ public function readLine(string $prefix = null): ?string
{
static $_rl = null;
@@ -255,11 +217,8 @@ class Kit extends Dispatcher\Kit
/**
* Read, edit, bind… a password from STDIN.
- *
- * @param string $prefix Prefix.
- * @return string
*/
- public function readPassword(string $prefix = null): string
+ public function readPassword(string $prefix = null): ?string
{
static $_rl = null;
diff --git a/Source/Exception.php b/Source/Exception.php
index a2337a5..e08380d 100644
--- a/Source/Exception.php
+++ b/Source/Exception.php
@@ -44,8 +44,6 @@ use Hoa\Exception as HoaException;
* Class \Hoa\Console\Exception.
*
* Extending the \Hoa\Exception\Exception class.
- *
- * @license New BSD License
*/
class Exception extends HoaException
{
diff --git a/Source/GetOption.php b/Source/GetOption.php
index 8c2d83c..ee2aee3 100644
--- a/Source/GetOption.php
+++ b/Source/GetOption.php
@@ -48,50 +48,36 @@ use Hoa\Ustring;
* interactivity, option name etc.
* And, of course, it proposes the getOption method, that allow user to loop
* easily the command options/arguments.
- *
- * @license New BSD License
*/
class GetOption
{
/**
* Argument: no argument is needed.
- *
- * @const int
*/
public const NO_ARGUMENT = 0;
/**
* Argument: required.
- *
- * @const int
*/
public const REQUIRED_ARGUMENT = 1;
/**
* Argument: optional.
- *
- * @const int
*/
public const OPTIONAL_ARGUMENT = 2;
/**
* Option bucket: name.
- *
- * @const int
*/
public const OPTION_NAME = 0;
/**
* Option bucket: has argument.
- *
- * @const int
*/
public const OPTION_HAS_ARG = 1;
/**
* Option bucket: value.
- *
- * @const int
*/
public const OPTION_VAL = 2;
@@ -105,22 +91,16 @@ class GetOption
* The has_arg is a constant: NO_ARGUMENT, REQUIRED_ARGUMENT, and
* OPTIONAL_ARGUMENT.
* The val is the short option value.
- *
- * @var array
*/
protected $_options = [];
/**
* Parser.
- *
- * @var \Hoa\Console\Parser
*/
protected $_parser = null;
/**
* The pipette contains all the short value of options.
- *
- * @var array
*/
protected $_pipette = [];
@@ -128,10 +108,6 @@ class GetOption
/**
* Prepare the pipette.
- *
- * @param array $options The option definition.
- * @param \Hoa\Console\Parser $parser The parser.
- * @throws \Hoa\Console\Exception
*/
public function __construct(array $options, Parser $parser)
{
@@ -231,15 +207,8 @@ class GetOption
/**
* Get option from the pipette.
- *
- * @param string &$optionValue Place a variable that will receive the
- * value of the current option.
- * @param string $short Short options to scan (in a single
- * string). If $short = null, all short
- * options will be selected.
- * @return mixed
*/
- public function getOption(&$optionValue, string $short = null)
+ public function getOption(?string &$optionValue, string $short = null)
{
static $first = true;
@@ -286,12 +255,10 @@ class GetOption
/**
* Check if the pipette is empty.
- *
- * @return bool
*/
public function isPipetteEmpty(): bool
{
- return count($this->_pipette) == 1;
+ return 1 === count($this->_pipette);
}
/**
@@ -299,12 +266,8 @@ class GetOption
* “ambiguous” in the self::__construct method.
* For a smarter resolving, you could use the console kit (please, see
* Hoa\Console\Dispatcher\Kit).
- *
- * @param array $solutions Solutions.
- * @return void
- * @throws \Hoa\Console\Exception
*/
- public function resolveOptionAmbiguity(array $solutions): void
+ public function resolveOptionAmbiguity(array $solutions)
{
if (!isset($solutions['solutions']) ||
!isset($solutions['value']) ||
diff --git a/Source/Input.php b/Source/Input.php
index 6a5126b..16b5453 100644
--- a/Source/Input.php
+++ b/Source/Input.php
@@ -47,15 +47,11 @@ use Hoa\Stream;
* This interface represents the input of a program. Most of the time, this is
* going to be `php://stdin` but it can be `/dev/tty` if the former has been
* closed.
- *
- * @license New BSD License
*/
class Input implements Stream\IStream\In
{
/**
* Real input stream.
- *
- * @var \Hoa\Stream\IStream\In
*/
protected $_input = null;
@@ -63,8 +59,6 @@ class Input implements Stream\IStream\In
/**
* Wraps an `Hoa\Stream\IStream\In` stream.
- *
- * @param \Hoa\Stream\IStream\In $input Input.
*/
public function __construct(Stream\IStream\In $input = null)
{
@@ -84,8 +78,6 @@ class Input implements Stream\IStream\In
/**
* Get underlying stream.
- *
- * @return \Hoa\Stream\IStream\In
*/
public function getStream(): Stream\IStream\In
{
@@ -94,8 +86,6 @@ class Input implements Stream\IStream\In
/**
* Test for end-of-file.
- *
- * @return bool
*/
public function eof(): bool
{
@@ -104,9 +94,6 @@ class Input implements Stream\IStream\In
/**
* Read n characters.
- *
- * @param int $length Length.
- * @return string
*/
public function read(int $length): string
{
@@ -115,9 +102,6 @@ class Input implements Stream\IStream\In
/**
* Alias of $this->read().
- *
- * @param int $length Length.
- * @return string
*/
public function readString(int $length): string
{
@@ -126,8 +110,6 @@ class Input implements Stream\IStream\In
/**
* Read a character.
- *
- * @return string
*/
public function readCharacter(): string
{
@@ -136,8 +118,6 @@ class Input implements Stream\IStream\In
/**
* Read a boolean.
- *
- * @return bool
*/
public function readBoolean(): bool
{
@@ -146,9 +126,6 @@ class Input implements Stream\IStream\In
/**
* Read an integer.
- *
- * @param int $length Length.
- * @return int
*/
public function readInteger(int $length = 1): int
{
@@ -157,9 +134,6 @@ class Input implements Stream\IStream\In
/**
* Read a float.
- *
- * @param int $length Length.
- * @return float
*/
public function readFloat(int $length = 1): float
{
@@ -169,10 +143,6 @@ class Input implements Stream\IStream\In
/**
* Read an array.
* Alias of the $this->scanf() method.
- *
- * @param mixed $argument Argument (because the behavior is very
- * different according to the implementation).
- * @return array
*/
public function readArray($argument = null): array
{
@@ -181,8 +151,6 @@ class Input implements Stream\IStream\In
/**
* Read a line.
- *
- * @return string
*/
public function readLine(): string
{
@@ -191,9 +159,6 @@ class Input implements Stream\IStream\In
/**
* Read all, i.e. read as much as possible.
- *
- * @param int $offset Offset.
- * @return string
*/
public function readAll(int $offset = 0): string
{
@@ -202,9 +167,6 @@ class Input implements Stream\IStream\In
/**
* Parse input from a stream according to a format.
- *
- * @param string $format Format (see printf's formats).
- * @return array
*/
public function scanf(string $format): array
{
diff --git a/Source/Mouse.php b/Source/Mouse.php
index f1a0af0..8af60f7 100644
--- a/Source/Mouse.php
+++ b/Source/Mouse.php
@@ -45,8 +45,6 @@ use Hoa\Event;
* Class \Hoa\Console\Mouse.
*
* Allow to listen the mouse.
- *
- * @license New BSD License
*/
class Mouse implements Event\Listenable
{
@@ -54,57 +52,41 @@ class Mouse implements Event\Listenable
/**
* Pointer code for left button.
- *
- * @const int
*/
public const BUTTON_LEFT = 0;
/**
* Pointer code for the middle button.
- *
- * @const int
*/
public const BUTTON_MIDDLE = 1;
/**
* Pointer code for the right button.
- *
- * @const int
*/
public const BUTTON_RIGHT = 2;
/**
* Pointer code for the release of the button.
- *
- * @const int
*/
public const BUTTON_RELEASE = 3;
/**
* Pointer code for the wheel up.
- *
- * @const int
*/
public const WHEEL_UP = 64;
/**
* Pointer code for the wheel down.
- *
- * @const int
*/
public const WHEEL_DOWN = 65;
/**
* Singleton.
- *
- * @var \Hoa\Console\Mouse
*/
protected static $_instance = null;
/**
* Whether the mouse is tracked or not.
- *
- * @var bool
*/
protected static $_enabled = false;
@@ -112,7 +94,6 @@ class Mouse implements Event\Listenable
/**
* Constructor.
- *
*/
private function __construct()
{
@@ -133,10 +114,8 @@ class Mouse implements Event\Listenable
/**
* Singleton.
- *
- * @return \Hoa\Console\Mouse
*/
- public static function getInstance(): Mouse
+ public static function getInstance(): self
{
if (null === static::$_instance) {
static::$_instance = new static();
@@ -147,10 +126,8 @@ class Mouse implements Event\Listenable
/**
* Track the mouse.
- *
- * @return bool
*/
- public static function track(): bool
+ public static function track()
{
if (true === static::$_enabled) {
return;
@@ -265,10 +242,8 @@ class Mouse implements Event\Listenable
/**
* Untrack the mouse.
- *
- * @return void
*/
- public static function untrack(): void
+ public static function untrack()
{
if (false === static::$_enabled) {
return;
diff --git a/Source/Output.php b/Source/Output.php
index c3d7cb8..d9141f0 100644
--- a/Source/Output.php
+++ b/Source/Output.php
@@ -45,22 +45,16 @@ use Hoa\Stream;
*
* This class represents the output of a program. Most of the time, this is
* going to be STDOUT.
- *
- * @license New BSD License
*/
class Output implements Stream\IStream\Out
{
/**
* Whether the multiplexer must be considered while writing on the output.
- *
- * @var bool
*/
protected $_considerMultiplexer = false;
/**
* Real output stream.
- *
- * @var \Hoa\Stream\IStream\Out
*/
protected $_output = null;
@@ -68,8 +62,6 @@ class Output implements Stream\IStream\Out
/**
* Wraps an `Hoa\Stream\IStream\Out` stream.
- *
- * @param \Hoa\Stream\IStream\Out $output Output.
*/
public function __construct(Stream\IStream\Out $output = null)
{
@@ -80,8 +72,6 @@ class Output implements Stream\IStream\Out
/**
* Get the real output stream.
- *
- * @return \Hoa\Stream\IStream\Out
*/
public function getStream(): Stream\IStream\Out
{
@@ -90,13 +80,8 @@ class Output implements Stream\IStream\Out
/**
* Write n characters.
- *
- * @param string $string String.
- * @param int $length Length.
- * @return void
- * @throws \Hoa\Console\Exception
*/
- public function write(string $string, int $length): void
+ public function write(string $string, int $length)
{
if (0 > $length) {
throw new Exception(
@@ -128,9 +113,6 @@ class Output implements Stream\IStream\Out
/**
* Write a string.
- *
- * @param string $string String.
- * @return void
*/
public function writeString(string $string)
{
@@ -141,9 +123,6 @@ class Output implements Stream\IStream\Out
/**
* Write a character.
- *
- * @param string $character Character.
- * @return void
*/
public function writeCharacter(string $character)
{
@@ -152,9 +131,6 @@ class Output implements Stream\IStream\Out
/**
* Write a boolean.
- *
- * @param bool $boolean Boolean.
- * @return void
*/
public function writeBoolean(bool $boolean)
{
@@ -163,9 +139,6 @@ class Output implements Stream\IStream\Out
/**
* Write an integer.
- *
- * @param int $integer Integer.
- * @return void
*/
public function writeInteger(int $integer)
{
@@ -176,9 +149,6 @@ class Output implements Stream\IStream\Out
/**
* Write a float.
- *
- * @param float $float Float.
- * @return void
*/
public function writeFloat(float $float)
{
@@ -189,9 +159,6 @@ class Output implements Stream\IStream\Out
/**
* Write an array.
- *
- * @param array $array Array.
- * @return void
*/
public function writeArray(array $array)
{
@@ -202,9 +169,6 @@ class Output implements Stream\IStream\Out
/**
* Write a line.
- *
- * @param string $line Line.
- * @return void
*/
public function writeLine(string $line)
{
@@ -219,9 +183,6 @@ class Output implements Stream\IStream\Out
/**
* Write all, i.e. as much as possible.
- *
- * @param string $string String.
- * @return void
*/
public function writeAll(string $string)
{
@@ -230,9 +191,6 @@ class Output implements Stream\IStream\Out
/**
* Truncate a stream to a given length.
- *
- * @param int $size Size.
- * @return bool
*/
public function truncate(int $size): bool
{
@@ -241,9 +199,6 @@ class Output implements Stream\IStream\Out
/**
* Consider the multiplexer (if running) while writing on the output.
- *
- * @param bool $consider Consider the multiplexer or not.
- * @return bool
*/
public function considerMultiplexer(bool $consider): bool
{
@@ -255,8 +210,6 @@ class Output implements Stream\IStream\Out
/**
* Check whether the multiplexer must be considered or not.
- *
- * @return bool
*/
public function isMultiplexerConsidered(): bool
{
diff --git a/Source/Parser.php b/Source/Parser.php
index fbadf56..a77a25e 100644
--- a/Source/Parser.php
+++ b/Source/Parser.php
@@ -48,15 +48,11 @@ class Parser
/**
* If long value is not enabled, -abc is equivalent to -a -b -c, else -abc
* is equivalent to --abc.
- *
- * @var \Hoa\Console\Parser
*/
protected $_longonly = false;
/**
* The parsed result in three categories : command, input, and switch.
- *
- * @var array
*/
protected $_parsed = null;
@@ -149,9 +145,6 @@ class Parser
* remove some character, or some particular case. But if we give the
* command manually — i.e. without any reconstitution —, all these cases
* will work :).
- *
- * @param string $command Command to parse.
- * @return void
*/
public function parse(string $command): void
{
@@ -234,15 +227,10 @@ class Parser
$this->addValuedSwitch($match);
}
}
-
- return;
}
/**
* Add an input.
- *
- * @param array $input Intput.
- * @return void
*/
protected function addInput(array $input): void
{
@@ -255,45 +243,28 @@ class Parser
}
$this->_parsed['input'][] = $handle;
-
- return;
}
/**
* Add a boolean switch.
- *
- * @param array $switch Switch.
- * @return void
*/
protected function addBoolSwitch(array $switch): void
{
$this->addSwitch($switch['b'], true);
-
- return;
}
/**
* Add a valued switch.
- *
- * @param array $switch Switch.
- * @return void
*/
protected function addValuedSwitch(array $switch): void
{
$this->addSwitch($switch['b'], $switch['s'], $switch[4]);
-
- return;
}
/**
* Add a switch.
- *
- * @param string $name Switch name.
- * @param string $value Switch value.
- * @param string $escape Character to escape.
- * @return void
*/
- protected function addSwitch(string $name, string $value, string $escape = null)
+ protected function addSwitch(string $name, $value, string $escape = null)
{
if (substr($name, 0, 2) == '--') {
return $this->addSwitch(substr($name, 2), $value, $escape);
@@ -340,12 +311,8 @@ class Parser
/**
* Transfer a switch value in the input stack.
- *
- * @param string $name The switch name.
- * @param string $value The switch value.
- * @return void
*/
- public function transferSwitchToInput(string $name, string &$value): void
+ public function transferSwitchToInput(string $name, string &$value)
{
if (!isset($this->_parsed['switch'][$name])) {
return;
@@ -360,8 +327,6 @@ class Parser
/**
* Get all inputs.
- *
- * @return array
*/
public function getInputs(): array
{
@@ -371,13 +336,6 @@ class Parser
/**
* Distribute inputs in variable (like the list() function, but without
* error).
- *
- * @param string $a First input.
- * @param string $b Second input.
- * @param string $c Third input.
- * @param ... ... ...
- * @param string $z 26th input.
- * @return void
*/
public function listInputs(
&$a,
@@ -418,8 +376,6 @@ class Parser
/**
* Get all switches.
- *
- * @return array
*/
public function getSwitches(): array
{
@@ -428,13 +384,6 @@ class Parser
/**
* Parse a special value, i.e. with comma and intervals.
- *
- * @param string $value The value to parse.
- * @param array $keywords Value of keywords.
- * @return array
- * @throws \Hoa\Console\Exception
- * @todo Could be ameliorate with a ":" explode, and some eval.
- * Check if operands are integer.
*/
public function parseSpecialValue(string $value, array $keywords = []): array
{
@@ -483,9 +432,6 @@ class Parser
/**
* Set the long-only parameter.
- *
- * @param bool $longonly The long-only value.
- * @return bool
*/
public function setLongOnly(bool $longonly = false): bool
{
@@ -497,8 +443,6 @@ class Parser
/**
* Get the long-only value.
- *
- * @return bool
*/
public function getLongOnly(): bool
{
diff --git a/Source/Processus.php b/Source/Processus.php
index 5592b14..6d7d6ae 100644
--- a/Source/Processus.php
+++ b/Source/Processus.php
@@ -297,7 +297,7 @@ class Processus extends Stream implements Stream\IStream\In, Stream\IStream\Out,
/**
* Open the stream and return the associated resource.
*/
- protected function &_open($streamName, Stream\Context $context = null)
+ protected function &_open(string $streamName, Stream\Context $context = null)
{
$out = @proc_open(
$streamName,
@@ -327,7 +327,7 @@ class Processus extends Stream implements Stream\IStream\In, Stream\IStream\Out,
@fclose($pipe);
}
- return @proc_close($this->getStream());
+ return (bool) @proc_close($this->getStream());
}
/**
@@ -559,7 +559,7 @@ class Processus extends Stream implements Stream\IStream\In, Stream\IStream\Out,
/**
* Read a line.
*/
- public function readLine(int $pipe = 1): string
+ public function readLine(int $pipe = 1)
{
return stream_get_line($this->getPipe($pipe), 1 << 15, "\n");
}
@@ -748,7 +748,7 @@ class Processus extends Stream implements Stream\IStream\In, Stream\IStream\Out,
/**
* Set command name.
*/
- protected function setCommand(string $command): string
+ protected function setCommand(string $command): ?string
{
$old = $this->_command;
$this->_command = escapeshellcmd($command);
@@ -759,7 +759,7 @@ class Processus extends Stream implements Stream\IStream\In, Stream\IStream\Out,
/**
* Get command name.
*/
- public function getCommand(): string
+ public function getCommand(): ?string
{
return $this->_command;
}
@@ -808,7 +808,7 @@ class Processus extends Stream implements Stream\IStream\In, Stream\IStream\Out,
/**
* Set current working directory of the process.
*/
- protected function setCwd(string $cwd): string
+ protected function setCwd(string $cwd): ?string
{
$old = $this->_cwd;
$this->_cwd = $cwd;
@@ -827,7 +827,7 @@ class Processus extends Stream implements Stream\IStream\In, Stream\IStream\Out,
/**
* Set environment of the process.
*/
- protected function setEnvironment(array $environment): array
+ protected function setEnvironment(array $environment): ?array
{
$old = $this->_environment;
$this->_environment = $environment;
@@ -838,7 +838,7 @@ class Processus extends Stream implements Stream\IStream\In, Stream\IStream\Out,
/**
* Get environment of the process.
*/
- public function getEnvironment(): array
+ public function getEnvironment(): ?array
{
return $this->_environment;
}
@@ -846,7 +846,7 @@ class Processus extends Stream implements Stream\IStream\In, Stream\IStream\Out,
/**
* Set timeout of the process.
*/
- public function setTimeout(int $timeout): int
+ public function setTimeout(int $timeout): ?int
{
$old = $this->_timeout;
$this->_timeout = $timeout;
@@ -868,14 +868,12 @@ class Processus extends Stream implements Stream\IStream\In, Stream\IStream\Out,
public static function setTitle(string $title): void
{
cli_set_process_title($title);
-
- return;
}
/**
* Get process title.
*/
- public static function getTitle(): string
+ public static function getTitle(): ?string
{
return cli_get_process_title();
}
@@ -883,7 +881,7 @@ class Processus extends Stream implements Stream\IStream\In, Stream\IStream\Out,
/**
* Found the place of a binary.
*/
- public static function locate(string $binary): string
+ public static function locate(string $binary): ?string
{
if (isset($_ENV['PATH'])) {
$separator = ':';
@@ -917,6 +915,6 @@ class Processus extends Stream implements Stream\IStream\In, Stream\IStream\Out,
$commandLine = escapeshellcmd($commandLine);
}
- return rtrim(shell_exec($commandLine));
+ return rtrim(shell_exec($commandLine) ?? '');
}
}
diff --git a/Source/Readline/Autocompleter/Aggregate.php b/Source/Readline/Autocompleter/Aggregate.php
index 0535ff2..dffc1d5 100644
--- a/Source/Readline/Autocompleter/Aggregate.php
+++ b/Source/Readline/Autocompleter/Aggregate.php
@@ -42,15 +42,11 @@ namespace Hoa\Console\Readline\Autocompleter;
* Class \Hoa\Console\Readline\Autocompleter\Aggregate.
*
* Aggregate several autocompleters.
- *
- * @license New BSD License
*/
class Aggregate implements Autocompleter
{
/**
* List of autocompleters.
- *
- * @var array
*/
protected $_autocompleters = null;
@@ -58,8 +54,6 @@ class Aggregate implements Autocompleter
/**
* Constructor.
- *
- * @param array $autocompleters Auto-completers.
*/
public function __construct(array $autocompleters)
{
@@ -71,11 +65,8 @@ class Aggregate implements Autocompleter
/**
* Complete a word.
* Returns null for no word, a full-word or an array of full-words.
- *
- * @param string &$prefix Prefix to autocomplete.
- * @return mixed
*/
- public function complete(&$prefix)
+ public function complete(?string &$prefix)
{
foreach ($this->getAutocompleters() as $autocompleter) {
$preg = preg_match(
@@ -104,11 +95,8 @@ class Aggregate implements Autocompleter
/**
* Set/initialize list of autocompleters.
- *
- * @param array $autocompleters Auto-completers.
- * @return \ArrayObject
*/
- protected function setAutocompleters(array $autocompleters): \ArrayObject
+ protected function setAutocompleters(array $autocompleters): ?\ArrayObject
{
$old = $this->_autocompleters;
$this->_autocompleters = new \ArrayObject($autocompleters);
@@ -118,18 +106,14 @@ class Aggregate implements Autocompleter
/**
* Get list of autocompleters.
- *
- * @return \ArrayObject
*/
- public function getAutocompleters(): \ArrayObject
+ public function getAutocompleters(): ?\ArrayObject
{
return $this->_autocompleters;
}
/**
* Get definition of a word.
- *
- * @return string
*/
public function getWordDefinition(): string
{
diff --git a/Source/Readline/Autocompleter/Autocompleter.php b/Source/Readline/Autocompleter/Autocompleter.php
index ca1dbec..6e06e51 100644
--- a/Source/Readline/Autocompleter/Autocompleter.php
+++ b/Source/Readline/Autocompleter/Autocompleter.php
@@ -44,25 +44,18 @@ use Hoa\Consistency;
* Interface \Hoa\Console\Readline\Autocompleter.
*
* Interface for all auto-completers.
- *
- * @license New BSD License
*/
interface Autocompleter
{
/**
* Complete a word.
* Returns null for no word, a full-word or an array of full-words.
- *
- * @param string &$prefix Prefix to autocomplete.
- * @return mixed
*/
- public function complete(&$prefix);
+ public function complete(?string &$prefix);
/**
* Get definition of a word.
* Example: \b\w+\b. PCRE delimiters and options must not be provided.
- *
- * @return string
*/
public function getWordDefinition(): string;
}
@@ -70,4 +63,4 @@ interface Autocompleter
/**
* Flex entity.
*/
-Consistency::flexEntity('Hoa\Console\Readline\Autocompleter\Autocompleter');
+Consistency::flexEntity(Autocompleter::class);
diff --git a/Source/Readline/Autocompleter/Path.php b/Source/Readline/Autocompleter/Path.php
index c66fe0b..b340b93 100644
--- a/Source/Readline/Autocompleter/Path.php
+++ b/Source/Readline/Autocompleter/Path.php
@@ -42,29 +42,21 @@ namespace Hoa\Console\Readline\Autocompleter;
* Class \Hoa\Console\Readline\Autocompleter\Path.
*
* Path autocompleter.
- *
- * @license New BSD License
*/
class Path implements Autocompleter
{
/**
* Root is the current working directory.
- *
- * @const string
*/
public const PWD = null;
/**
* Root.
- *
- * @var string
*/
protected $_root = null;
/**
* Iterator factory. Please, see the self::setIteratorFactory method.
- *
- * @var \Closure
*/
protected $_iteratorFactory = null;
@@ -72,15 +64,10 @@ class Path implements Autocompleter
/**
* Constructor.
- *
- * @param string $root Root.
- * @param \Closure $iteratorFactory Iterator factory (please, see
- * the self::setIteratorFactory
- * method).
*/
public function __construct(
- string $root = null,
- \Closure $iteratorFactory = null
+ string $root = null,
+ callable $iteratorFactory = null
) {
if (null === $root) {
$root = static::PWD;
@@ -91,18 +78,13 @@ class Path implements Autocompleter
if (null !== $iteratorFactory) {
$this->setIteratorFactory($iteratorFactory);
}
-
- return;
}
/**
* Complete a word.
* Returns null for no word, a full-word or an array of full-words.
- *
- * @param string &$prefix Prefix to autocomplete.
- * @return mixed
*/
- public function complete(&$prefix)
+ public function complete(?string &$prefix)
{
$root = $this->getRoot();
@@ -158,8 +140,6 @@ class Path implements Autocompleter
/**
* Get definition of a word.
- *
- * @return string
*/
public function getWordDefinition(): string
{
@@ -168,11 +148,8 @@ class Path implements Autocompleter
/**
* Set root.
- *
- * @param string $root Root.
- * @return string
*/
- public function setRoot(string $root): string
+ public function setRoot(string $root): ?string
{
$old = $this->_root;
$this->_root = $root;
@@ -182,22 +159,16 @@ class Path implements Autocompleter
/**
* Get root.
- *
- * @return string
*/
- public function getRoot(): string
+ public function getRoot(): ?string
{
return $this->_root;
}
/**
* Set iterator factory (a finder).
- *
- * @param \Closure $iteratorFactory Closore with a single argument:
- * $path of the iterator.
- * @return string
*/
- public function setIteratorFactory(\Closure $iteratorFactory): string
+ public function setIteratorFactory(callable $iteratorFactory): ?string
{
$old = $this->_iteratorFactory;
$this->_iteratorFactory = $iteratorFactory;
@@ -207,20 +178,16 @@ class Path implements Autocompleter
/**
* Get iterator factory.
- *
- * @return \Closure
*/
- public function getIteratorFactory(): \Closure
+ public function getIteratorFactory(): callable
{
return $this->_iteratorFactory;
}
/**
* Get default iterator factory (based on \DirectoryIterator).
- *
- * @return \Closure
*/
- public static function getDefaultIteratorFactory(): \Closure
+ public static function getDefaultIteratorFactory(): callable
{
return function ($path) {
return new \DirectoryIterator($path);
diff --git a/Source/Readline/Autocompleter/Word.php b/Source/Readline/Autocompleter/Word.php
index a674c72..757cb35 100644
--- a/Source/Readline/Autocompleter/Word.php
+++ b/Source/Readline/Autocompleter/Word.php
@@ -42,15 +42,11 @@ namespace Hoa\Console\Readline\Autocompleter;
* Class \Hoa\Console\Readline\Autocompleter\Word.
*
* The simplest auto-completer: complete a word.
- *
- * @license New BSD License
*/
class Word implements Autocompleter
{
/**
* List of words.
- *
- * @var array
*/
protected $_words = null;
@@ -58,24 +54,17 @@ class Word implements Autocompleter
/**
* Constructor.
- *
- * @param array $words Words.
*/
public function __construct(array $words)
{
$this->setWords($words);
-
- return;
}
/**
* Complete a word.
* Returns null for no word, a full-word or an array of full-words.
- *
- * @param string &$prefix Prefix to autocomplete.
- * @return mixed
*/
- public function complete(&$prefix)
+ public function complete(?string &$prefix)
{
$out = [];
$length = mb_strlen($prefix);
@@ -99,8 +88,6 @@ class Word implements Autocompleter
/**
* Get definition of a word.
- *
- * @return string
*/
public function getWordDefinition(): string
{
@@ -109,11 +96,8 @@ class Word implements Autocompleter
/**
* Set list of words.
- *
- * @param array $words Words.
- * @return array
*/
- public function setWords(array $words): array
+ public function setWords(array $words): ?array
{
$old = $this->_words;
$this->_words = $words;
@@ -123,8 +107,6 @@ class Word implements Autocompleter
/**
* Get list of words.
- *
- * @return array
*/
public function getWords(): array
{
diff --git a/Source/Readline/Password.php b/Source/Readline/Password.php
index 65d135a..8cc9b04 100644
--- a/Source/Readline/Password.php
+++ b/Source/Readline/Password.php
@@ -42,15 +42,11 @@ namespace Hoa\Console\Readline;
* Class \Hoa\Console\Readline\Password.
*
* Read, edit, bind… a password from the input.
- *
- * @license New BSD License
*/
class Password extends Readline
{
/**
* State: continue to read and no output.
- *
- * @const int
*/
- public const STATE_CONTINUE = 5; // parent::STATE_CONTINUE | parent::STATE_NO_ECHO
+ public const STATE_CONTINUE = parent::STATE_CONTINUE | parent::STATE_NO_ECHO;
}
diff --git a/Source/Readline/Readline.php b/Source/Readline/Readline.php
index 07bd57b..679f6d8 100644
--- a/Source/Readline/Readline.php
+++ b/Source/Readline/Readline.php
@@ -46,99 +46,71 @@ use Hoa\Ustring;
* Class \Hoa\Console\Readline.
*
* Read, edit, bind… a line from the input.
- *
- * @license New BSD License
*/
class Readline
{
/**
* State: continue to read.
- *
- * @const int
*/
public const STATE_CONTINUE = 1;
/**
* State: stop to read.
- *
- * @const int
*/
public const STATE_BREAK = 2;
/**
* State: no output the current buffer.
- *
- * @const int
*/
public const STATE_NO_ECHO = 4;
/**
* Current editing line.
- *
- * @var string
*/
protected $_line = null;
/**
* Current editing line seek.
- *
- * @var int
*/
protected $_lineCurrent = 0;
/**
* Current editing line length.
- *
- * @var int
*/
protected $_lineLength = 0;
/**
* Current buffer (most of the time, a char).
- *
- * @var string
*/
protected $_buffer = null;
/**
* Mapping.
- *
- * @var array
*/
protected $_mapping = [];
/**
* History.
- *
- * @var array
*/
protected $_history = [];
/**
* History current position.
- *
- * @var int
*/
protected $_historyCurrent = 0;
/**
* History size.
- *
- * @var int
*/
protected $_historySize = 0;
/**
* Prefix.
- *
- * @var string
*/
protected $_prefix = null;
/**
* Autocompleter.
- *
- * @var \Hoa\Console\Readline\Autocompleter
*/
protected $_autocompleter = null;
@@ -146,7 +118,6 @@ class Readline
/**
* Initialize the readline editor.
- *
*/
public function __construct()
{
@@ -173,11 +144,8 @@ class Readline
/**
* Read a line from the input.
- *
- * @param string $prefix Prefix.
- * @return string
*/
- public function readLine(string $prefix = null): string
+ public function readLine(string $prefix = null): ?string
{
$input = Console::getInput();
@@ -238,11 +206,8 @@ class Readline
/**
* Readline core.
- *
- * @param string $char Char.
- * @return string
*/
- public function _readLine(string $char): string
+ public function _readLine(string $char): ?string
{
if (isset($this->_mapping[$char]) &&
is_callable($this->_mapping[$char])) {
@@ -280,17 +245,12 @@ class Readline
/**
* Add mappings.
- *
- * @param array $mappings Mappings.
- * @return void
*/
public function addMappings(array $mappings): void
{
foreach ($mappings as $key => $mapping) {
$this->addMapping($key, $mapping);
}
-
- return;
}
/**
@@ -301,10 +261,6 @@ class Readline
* • abc for a simple mapping.
* A mapping is a callable that has only one parameter of type
* Hoa\Console\Readline and that returns a self::STATE_* constant.
- *
- * @param string $key Key.
- * @param mixed $mapping Mapping (a callable).
- * @return void
*/
public function addMapping(string $key, $mapping): void
{
@@ -316,17 +272,12 @@ class Readline
} else {
$this->_mapping[$key] = $mapping;
}
-
- return;
}
/**
* Add an entry in the history.
- *
- * @param string $line Line.
- * @return void
*/
- public function addHistory(string $line = null): void
+ public function addHistory(string $line = null)
{
if (empty($line)) {
return;
@@ -334,14 +285,10 @@ class Readline
$this->_history[] = $line;
$this->_historyCurrent = $this->_historySize++;
-
- return;
}
/**
* Clear history.
- *
- * @return void
*/
public function clearHistory(): void
{
@@ -349,17 +296,12 @@ class Readline
$this->_history = [];
$this->_historyCurrent = 0;
$this->_historySize = 1;
-
- return;
}
/**
* Get an entry in the history.
- *
- * @param int $i Index of the entry.
- * @return string
*/
- public function getHistory(int $i = null): string
+ public function getHistory(int $i = null): ?string
{
if (null === $i) {
$i = $this->_historyCurrent;
@@ -374,10 +316,8 @@ class Readline
/**
* Go backward in the history.
- *
- * @return string
*/
- public function previousHistory(): string
+ public function previousHistory(): ?string
{
if (0 >= $this->_historyCurrent) {
return $this->getHistory(0);
@@ -388,10 +328,8 @@ class Readline
/**
* Go forward in the history.
- *
- * @return string
*/
- public function nextHistory(): string
+ public function nextHistory(): ?string
{
if ($this->_historyCurrent + 1 >= $this->_historySize) {
return $this->getLine();
@@ -402,34 +340,24 @@ class Readline
/**
* Get current line.
- *
- * @return string
*/
- public function getLine(): string
+ public function getLine(): ?string
{
return $this->_line;
}
/**
* Append to current line.
- *
- * @param string $append String to append.
- * @return void
*/
public function appendLine(string $append): void
{
$this->_line .= $append;
$this->_lineLength = mb_strlen($this->_line);
$this->_lineCurrent = $this->_lineLength;
-
- return;
}
/**
* Insert into current line at the current seek.
- *
- * @param string $insert String to insert.
- * @return void
*/
public function insertLine(string $insert)
{
@@ -448,22 +376,16 @@ class Readline
/**
* Reset current line.
- *
- * @return void
*/
protected function resetLine(): void
{
$this->_line = null;
$this->_lineCurrent = 0;
$this->_lineLength = 0;
-
- return;
}
/**
* Get current line seek.
- *
- * @return int
*/
public function getLineCurrent(): int
{
@@ -482,44 +404,32 @@ class Readline
/**
* Set prefix.
- *
- * @param string $prefix Prefix.
- * @return void
*/
public function setPrefix(string $prefix): void
{
$this->_prefix = $prefix;
-
- return;
}
/**
* Get prefix.
- *
- * @return string
*/
- public function getPrefix(): string
+ public function getPrefix(): ?string
{
return $this->_prefix;
}
/**
* Get buffer. Not for user.
- *
- * @return string
*/
- public function getBuffer(): string
+ public function getBuffer(): ?string
{
return $this->_buffer;
}
/**
* Set an autocompleter.
- *
- * @param \Hoa\Console\Readline\Autocompleter $autocompleter Auto-completer.
- * @return \Hoa\Console\Readline\Autocompleter
*/
- public function setAutocompleter(Autocompleter $autocompleter): Autocompleter
+ public function setAutocompleter(Autocompleter $autocompleter): ?Autocompleter
{
$old = $this->_autocompleter;
$this->_autocompleter = $autocompleter;
@@ -529,8 +439,6 @@ class Readline
/**
* Get the autocompleter.
- *
- * @return \Hoa\Console\Readline\Autocompleter
*/
public function getAutocompleter(): Autocompleter
{
@@ -539,9 +447,6 @@ class Readline
/**
* Read on input. Not for user.
- *
- * @param int $length Length.
- * @return string
*/
public function _read(int $length = 512): string
{
@@ -550,52 +455,34 @@ class Readline
/**
* Set current line. Not for user.
- *
- * @param string $line Line.
- * @return void
*/
public function setLine(string $line): void
{
$this->_line = $line;
$this->_lineLength = mb_strlen($this->_line);
$this->_lineCurrent = $this->_lineLength;
-
- return;
}
/**
* Set current line seek. Not for user.
- *
- * @param int $current Seek.
- * @return void
*/
public function setLineCurrent(int $current): void
{
$this->_lineCurrent = $current;
-
- return;
}
/**
* Set line length. Not for user.
- *
- * @param int $length Length.
- * @return void
*/
public function setLineLength(int $length): void
{
$this->_lineLength = $length;
-
- return;
}
/**
* Set buffer. Not for user.
- *
- * @param string $buffer Buffer.
- * @return string
*/
- public function setBuffer(string $buffer): string
+ public function setBuffer(string $buffer): ?string
{
$this->_buffer = $buffer;
@@ -605,11 +492,8 @@ class Readline
/**
* Up arrow binding.
* Go backward in the history.
- *
- * @param \Hoa\Console\Readline $self Self.
- * @return int
*/
- public function _bindArrowUp(Readline $self): int
+ public function _bindArrowUp(self $self): int
{
if (0 === (static::STATE_CONTINUE & static::STATE_NO_ECHO)) {
Console\Cursor::clear('↔');
@@ -625,10 +509,8 @@ class Readline
* Down arrow binding.
* Go forward in the history.
*
- * @param \Hoa\Console\Readline $self Self.
- * @return int
*/
- public function _bindArrowDown(Readline $self): int
+ public function _bindArrowDown(self $self): int
{
if (0 === (static::STATE_CONTINUE & static::STATE_NO_ECHO)) {
Console\Cursor::clear('↔');
@@ -644,11 +526,8 @@ class Readline
/**
* Right arrow binding.
* Move cursor to the right.
- *
- * @param \Hoa\Console\Readline $self Self.
- * @return int
*/
- public function _bindArrowRight(Readline $self): int
+ public function _bindArrowRight(self $self): int
{
if ($self->getLineLength() > $self->getLineCurrent()) {
if (0 === (static::STATE_CONTINUE & static::STATE_NO_ECHO)) {
@@ -666,11 +545,8 @@ class Readline
/**
* Left arrow binding.
* Move cursor to the left.
- *
- * @param \Hoa\Console\Readline $self Self.
- * @return int
*/
- public function _bindArrowLeft(Readline $self): int
+ public function _bindArrowLeft(self $self): int
{
if (0 < $self->getLineCurrent()) {
if (0 === (static::STATE_CONTINUE & static::STATE_NO_ECHO)) {
@@ -688,11 +564,8 @@ class Readline
/**
* Backspace and Control-H binding.
* Delete the first character at the right of the cursor.
- *
- * @param \Hoa\Console\Readline $self Self.
- * @return int
*/
- public function _bindBackspace(Readline $self): int
+ public function _bindBackspace(self $self): int
{
$buffer = null;
@@ -722,11 +595,8 @@ class Readline
/**
* Control-A binding.
* Move cursor to beginning of line.
- *
- * @param \Hoa\Console\Readline $self Self.
- * @return int
*/
- public function _bindControlA(Readline $self): int
+ public function _bindControlA(self $self): int
{
for ($i = $self->getLineCurrent() - 1; 0 <= $i; --$i) {
$self->_bindArrowLeft($self);
@@ -738,11 +608,8 @@ class Readline
/**
* Control-B binding.
* Move cursor backward one word.
- *
- * @param \Hoa\Console\Readline $self Self.
- * @return int
*/
- public function _bindControlB(Readline $self): int
+ public function _bindControlB(self $self): int
{
$current = $self->getLineCurrent();
@@ -773,11 +640,8 @@ class Readline
/**
* Control-E binding.
* Move cursor to end of line.
- *
- * @param \Hoa\Console\Readline $self Self.
- * @return int
*/
- public function _bindControlE(Readline $self): int
+ public function _bindControlE(self $self): int
{
for (
$i = $self->getLineCurrent(), $max = $self->getLineLength();
@@ -793,11 +657,8 @@ class Readline
/**
* Control-F binding.
* Move cursor forward one word.
- *
- * @param \Hoa\Console\Readline $self Self.
- * @return int
*/
- public function _bindControlF(Readline $self): int
+ public function _bindControlF(self $self): int
{
$current = $self->getLineCurrent();
@@ -832,11 +693,8 @@ class Readline
/**
* Control-W binding.
* Delete first backward word.
- *
- * @param \Hoa\Console\Readline $self Self.
- * @return int
*/
- public function _bindControlW(Readline $self): int
+ public function _bindControlW(self $self): int
{
$current = $self->getLineCurrent();
@@ -866,11 +724,8 @@ class Readline
/**
* Newline binding.
- *
- * @param \Hoa\Console\Readline $self Self.
- * @return int
*/
- public function _bindNewline(Readline $self): int
+ public function _bindNewline(self $self): int
{
$self->addHistory($self->getLine());
@@ -879,11 +734,8 @@ class Readline
/**
* Tab binding.
- *
- * @param \Hoa\Console\Readline $self Self.
- * @return int
*/
- public function _bindTab(Readline $self): int
+ public function _bindTab(self $self): int
{
$output = Console::getOutput();
$autocompleter = $self->getAutocompleter();
@@ -1185,4 +1037,4 @@ Console::advancedInteraction();
/**
* Flex entity.
*/
-Consistency::flexEntity('Hoa\Console\Readline\Readline');
+Consistency::flexEntity(Readline::class);
diff --git a/Source/Tput.php b/Source/Tput.php
index 2fe208d..defe2c4 100644
--- a/Source/Tput.php
+++ b/Source/Tput.php
@@ -716,7 +716,7 @@ class Tput
/**
* Get a boolean value.
*/
- public function has(bool $boolean): bool
+ public function has(string $boolean): bool
{
if (!isset($this->_informations['booleans'][$boolean])) {
return false;
@@ -728,7 +728,7 @@ class Tput
/**
* Get a number value.
*/
- public function count(int $number): int
+ public function count(string $number): int
{
if (!isset($this->_informations['numbers'][$number])) {
return 0;
diff --git a/Source/Window.php b/Source/Window.php
index 8b84d8b..a3b09a1 100644
--- a/Source/Window.php
+++ b/Source/Window.php
@@ -204,7 +204,7 @@ class Window implements Event\Source
public static function getPosition(): array
{
if (OS_WIN) {
- return;
+ return ['x' => 0, 'y' => 0];
}
// DECSLPP.
@@ -387,7 +387,7 @@ class Window implements Event\Source
public static function getTitle(): ?string
{
if (OS_WIN) {
- return;
+ return null;
}
// DECSLPP.
@@ -431,7 +431,7 @@ class Window implements Event\Source
public static function getLabel(): ?string
{
if (OS_WIN) {
- return;
+ return null;
}
// DECSLPP.