diff --git a/libs/cli-utils/example/down.php b/libs/cli-utils/example/down.php index 33a76d9..271c5e0 100644 --- a/libs/cli-utils/example/down.php +++ b/libs/cli-utils/example/down.php @@ -9,7 +9,7 @@ $app = new \Toolkit\Cli\App(); $url = 'http://no2.php.net/distributions/php-7.2.5.tar.bz2'; -$down = Download::create($url, ''); +$down = Download::create($url); $type = $app->getOpt('type', 'text'); diff --git a/libs/cli-utils/src/App.php b/libs/cli-utils/src/App.php index 66434cd..5bf08bf 100644 --- a/libs/cli-utils/src/App.php +++ b/libs/cli-utils/src/App.php @@ -28,7 +28,7 @@ class App private $opts = []; /** @var string */ - private $script = ''; + private $script; /** @var string */ private $command = ''; @@ -68,7 +68,7 @@ public function __construct(array $argv = null) * @param bool $exit * @throws \InvalidArgumentException */ - public function run(bool $exit = true) + public function run(bool $exit = true): void { if (isset($this->args[0])) { $this->command = $this->args[0]; @@ -82,7 +82,7 @@ public function run(bool $exit = true) * @param bool $exit * @throws \InvalidArgumentException */ - public function dispatch(bool $exit = true) + public function dispatch(bool $exit = true): void { if (!$command = $this->command) { $this->displayHelp(); @@ -109,7 +109,7 @@ public function dispatch(bool $exit = true) /** * @param int $code */ - public function stop($code = 0) + public function stop($code = 0): void { exit((int)$code); } @@ -172,7 +172,7 @@ protected function handleException(\Throwable $e): int * @param string $description * @throws \InvalidArgumentException */ - public function addCommand(string $command, callable $handler, string $description = '') + public function addCommand(string $command, callable $handler, string $description = ''): void { if (!$command || !$handler) { throw new \InvalidArgumentException('Invalid arguments'); @@ -186,7 +186,7 @@ public function addCommand(string $command, callable $handler, string $descripti * @param array $commands * @throws \InvalidArgumentException */ - public function commands(array $commands) + public function commands(array $commands): void { foreach ($commands as $command => $handler) { $des = ''; @@ -208,7 +208,7 @@ public function commands(array $commands) /** * @param string $err */ - public function displayHelp(string $err = '') + public function displayHelp(string $err = ''): void { if ($err) { echo Color::render("ERROR: $err\n\n"); @@ -263,7 +263,7 @@ public function getArgs(): array /** * @param array $args */ - public function setArgs(array $args) + public function setArgs(array $args): void { $this->args = $args; } @@ -279,7 +279,7 @@ public function getOpts(): array /** * @param array $opts */ - public function setOpts(array $opts) + public function setOpts(array $opts): void { $this->opts = $opts; } @@ -295,7 +295,7 @@ public function getScript(): string /** * @param string $script */ - public function setScript(string $script) + public function setScript(string $script): void { $this->script = $script; } @@ -311,7 +311,7 @@ public function getCommand(): string /** * @param string $command */ - public function setCommand(string $command) + public function setCommand(string $command): void { $this->command = $command; } diff --git a/libs/cli-utils/src/Cli.php b/libs/cli-utils/src/Cli.php index 96ca5f9..54a47fd 100644 --- a/libs/cli-utils/src/Cli.php +++ b/libs/cli-utils/src/Cli.php @@ -38,7 +38,7 @@ public static function read($message = null, $nl = false): string * @param bool $nl * @param bool $quit */ - public static function write($messages, $nl = true, $quit = false) + public static function write($messages, $nl = true, $quit = false): void { if (\is_array($messages)) { $messages = implode($nl ? \PHP_EOL : '', $messages); @@ -53,7 +53,7 @@ public static function write($messages, $nl = true, $quit = false) * @param bool $nl * @param bool|int $quit */ - public static function stdout(string $message, $nl = true, $quit = false) + public static function stdout(string $message, $nl = true, $quit = false): void { fwrite(\STDOUT, $message . ($nl ? \PHP_EOL : '')); fflush(\STDOUT); @@ -70,7 +70,7 @@ public static function stdout(string $message, $nl = true, $quit = false) * @param bool $nl * @param bool|int $quit */ - public static function stderr(string $message, $nl = true, $quit = -1) + public static function stderr(string $message, $nl = true, $quit = -1): void { fwrite(\STDERR, self::color('[ERROR] ', 'red') . $message . ($nl ? PHP_EOL : '')); fflush(\STDOUT); diff --git a/libs/cli-utils/src/Console.php b/libs/cli-utils/src/Console.php index bbd7cfa..e7d2ccf 100644 --- a/libs/cli-utils/src/Console.php +++ b/libs/cli-utils/src/Console.php @@ -36,7 +36,7 @@ class Console extends Cli * 'coId' => 12, * ] */ - public static function log(string $msg, array $data = [], string $type = 'info', array $opts = []) + public static function log(string $msg, array $data = [], string $type = 'info', array $opts = []): void { if (isset(self::LOG_LEVEL2TAG[$type])) { $type = ColorTag::add(\strtoupper($type), self::LOG_LEVEL2TAG[$type]); diff --git a/libs/cli-utils/src/Download.php b/libs/cli-utils/src/Download.php index e3e44cd..22c7dc4 100644 --- a/libs/cli-utils/src/Download.php +++ b/libs/cli-utils/src/Download.php @@ -35,7 +35,7 @@ final class Download * @param string $type * @return Download */ - public static function create(string $url, string $saveAs = '', string $type = self::PROGRESS_TEXT) + public static function create(string $url, string $saveAs = '', string $type = self::PROGRESS_TEXT): Download { return new self($url, $saveAs, $type); } @@ -122,7 +122,7 @@ public function start(): self * @param int $transferredBytes Have been transferred bytes * @param int $maxBytes Target max length bytes */ - public function progressShow($notifyCode, $severity, $message, $messageCode, $transferredBytes, $maxBytes) + public function progressShow($notifyCode, $severity, $message, $messageCode, $transferredBytes, $maxBytes): void { $msg = ''; @@ -205,7 +205,7 @@ public function getShowType(): string /** * @param string $showType */ - public function setShowType(string $showType) + public function setShowType(string $showType): void { $this->showType = $showType; } @@ -221,7 +221,7 @@ public function getUrl(): string /** * @param string $url */ - public function setUrl(string $url) + public function setUrl(string $url): void { $this->url = \trim($url); } @@ -237,7 +237,7 @@ public function getSaveAs(): string /** * @param string $saveAs */ - public function setSaveAs(string $saveAs) + public function setSaveAs(string $saveAs): void { $this->saveAs = \trim($saveAs); } diff --git a/libs/cli-utils/src/Flags.php b/libs/cli-utils/src/Flags.php index 051601a..0f4be6a 100644 --- a/libs/cli-utils/src/Flags.php +++ b/libs/cli-utils/src/Flags.php @@ -36,13 +36,13 @@ public static function simpleParseArgv(array $argv): array } if (\strpos($value, '=')) { - list($n, $v) = \explode('=', $value); + [$n, $v] = \explode('=', $value); $opts[$n] = $v; } else { $opts[$value] = true; } } elseif (\strpos($value, '=')) { - list($n, $v) = \explode('=', $value); + [$n, $v] = \explode('=', $value); $args[$n] = $v; } else { $args[] = $value; @@ -122,12 +122,12 @@ public static function parseArgv(array $params, array $config = []): array // long-opt: value specified inline (--=) if (\strpos($option, '=') !== false) { - list($option, $value) = \explode('=', $option, 2); + [$option, $value] = \explode('=', $option, 2); } // short-opt: value specified inline (-=) } elseif (isset($option{1}) && $option{1} === '=') { - list($option, $value) = \explode('=', $option, 2); + [$option, $value] = \explode('=', $option, 2); } // check if next parameter is a descriptor or a value @@ -170,7 +170,7 @@ public static function parseArgv(array $params, array $config = []): array // value specified inline (=) if (\strpos($p, '=') !== false) { - list($name, $value) = \explode('=', $p, 2); + [$name, $value] = \explode('=', $p, 2); $args[$name] = self::filterBool($value); } else { $args[] = $p; @@ -232,7 +232,7 @@ public static function parseArray(array $params): array * @todo ... * @param string $string */ - public static function parseString(string $string) + public static function parseString(string $string): void { } diff --git a/libs/cli-utils/src/Highlighter.php b/libs/cli-utils/src/Highlighter.php index c68a10e..dc166f8 100644 --- a/libs/cli-utils/src/Highlighter.php +++ b/libs/cli-utils/src/Highlighter.php @@ -250,7 +250,7 @@ private function colorLines(array $tokenLines): array foreach ($tokenLines as $lineCount => $tokenLine) { $line = ''; - foreach ($tokenLine as list($tokenType, $tokenValue)) { + foreach ($tokenLine as [$tokenType, $tokenValue]) { $style = $this->defaultTheme[$tokenType]; if (Color::hasStyle($style)) { @@ -308,7 +308,7 @@ public function getDefaultTheme(): array /** * @param array $defaultTheme */ - public function setDefaultTheme(array $defaultTheme) + public function setDefaultTheme(array $defaultTheme): void { $this->defaultTheme = \array_merge($this->defaultTheme, $defaultTheme); } diff --git a/libs/cli-utils/src/Terminal.php b/libs/cli-utils/src/Terminal.php index 4e72888..096a0a8 100644 --- a/libs/cli-utils/src/Terminal.php +++ b/libs/cli-utils/src/Terminal.php @@ -157,7 +157,7 @@ public static function build($format, $type = 'm'): string public function cursor($typeName, $arg1 = 1, $arg2 = null): self { if (!isset(self::$ctrlCursorCodes[$typeName])) { - Cli::stderr("The [$typeName] is not supported cursor control.", true); + Cli::stderr("The [$typeName] is not supported cursor control."); } $code = self::$ctrlCursorCodes[$typeName]; @@ -208,7 +208,7 @@ public function screen(string $typeName, $arg = null): self return $this; } - public function reset() + public function reset(): void { echo self::END_CHAR; } diff --git a/libs/cli-utils/test/ColorTagTest.php b/libs/cli-utils/test/ColorTagTest.php index 25ac519..223589a 100644 --- a/libs/cli-utils/test/ColorTagTest.php +++ b/libs/cli-utils/test/ColorTagTest.php @@ -17,7 +17,7 @@ */ class ColorTagTest extends TestCase { - public function testStrip() + public function testStrip(): void { $text = ColorTag::strip('text'); $this->assertSame('text', $text); @@ -27,7 +27,7 @@ public function testStrip() $this->assertSame('text', $text); } - public function testWrap() + public function testWrap(): void { $text = ColorTag::wrap('text', 'tag'); $this->assertSame('text', $text); @@ -39,7 +39,7 @@ public function testWrap() $this->assertSame('', $text); } - public function testExists() + public function testExists(): void { $this->assertTrue(ColorTag::exists('text')); $this->assertFalse(ColorTag::exists('text'));