Skip to content

Commit

Permalink
format codes. declare return type
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Feb 2, 2019
1 parent 5806ef8 commit 08e24c7
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion libs/cli-utils/example/down.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
22 changes: 11 additions & 11 deletions libs/cli-utils/src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class App
private $opts = [];

/** @var string */
private $script = '';
private $script;

/** @var string */
private $command = '';
Expand Down Expand Up @@ -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];
Expand All @@ -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();
Expand All @@ -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);
}
Expand Down Expand Up @@ -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');
Expand All @@ -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 = '';
Expand All @@ -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("<red>ERROR</red>: $err\n\n");
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions libs/cli-utils/src/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libs/cli-utils/src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
10 changes: 5 additions & 5 deletions libs/cli-utils/src/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 = '';

Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions libs/cli-utils/src/Flags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,12 +122,12 @@ public static function parseArgv(array $params, array $config = []): array

// long-opt: value specified inline (--<opt>=<value>)
if (\strpos($option, '=') !== false) {
list($option, $value) = \explode('=', $option, 2);
[$option, $value] = \explode('=', $option, 2);
}

// short-opt: value specified inline (-<opt>=<value>)
} 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
Expand Down Expand Up @@ -170,7 +170,7 @@ public static function parseArgv(array $params, array $config = []): array

// value specified inline (<arg>=<value>)
if (\strpos($p, '=') !== false) {
list($name, $value) = \explode('=', $p, 2);
[$name, $value] = \explode('=', $p, 2);
$args[$name] = self::filterBool($value);
} else {
$args[] = $p;
Expand Down Expand Up @@ -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
{

}
Expand Down
4 changes: 2 additions & 2 deletions libs/cli-utils/src/Highlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions libs/cli-utils/src/Terminal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions libs/cli-utils/test/ColorTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class ColorTagTest extends TestCase
{
public function testStrip()
public function testStrip(): void
{
$text = ColorTag::strip('<tag>text</tag>');
$this->assertSame('text', $text);
Expand All @@ -27,7 +27,7 @@ public function testStrip()
$this->assertSame('<tag>text<tag>', $text);
}

public function testWrap()
public function testWrap(): void
{
$text = ColorTag::wrap('text', 'tag');
$this->assertSame('<tag>text</tag>', $text);
Expand All @@ -39,7 +39,7 @@ public function testWrap()
$this->assertSame('', $text);
}

public function testExists()
public function testExists(): void
{
$this->assertTrue(ColorTag::exists('<tag>text</tag>'));
$this->assertFalse(ColorTag::exists('text'));
Expand Down

0 comments on commit 08e24c7

Please sign in to comment.