Skip to content

Commit 423397e

Browse files
committed
format codes. declare return type
1 parent ed949ee commit 423397e

File tree

9 files changed

+34
-34
lines changed

9 files changed

+34
-34
lines changed

example/down.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
$app = new \Toolkit\Cli\App();
1111
$url = 'http://no2.php.net/distributions/php-7.2.5.tar.bz2';
12-
$down = Download::create($url, '');
12+
$down = Download::create($url);
1313

1414
$type = $app->getOpt('type', 'text');
1515

src/App.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class App
2828
private $opts = [];
2929

3030
/** @var string */
31-
private $script = '';
31+
private $script;
3232

3333
/** @var string */
3434
private $command = '';
@@ -68,7 +68,7 @@ public function __construct(array $argv = null)
6868
* @param bool $exit
6969
* @throws \InvalidArgumentException
7070
*/
71-
public function run(bool $exit = true)
71+
public function run(bool $exit = true): void
7272
{
7373
if (isset($this->args[0])) {
7474
$this->command = $this->args[0];
@@ -82,7 +82,7 @@ public function run(bool $exit = true)
8282
* @param bool $exit
8383
* @throws \InvalidArgumentException
8484
*/
85-
public function dispatch(bool $exit = true)
85+
public function dispatch(bool $exit = true): void
8686
{
8787
if (!$command = $this->command) {
8888
$this->displayHelp();
@@ -109,7 +109,7 @@ public function dispatch(bool $exit = true)
109109
/**
110110
* @param int $code
111111
*/
112-
public function stop($code = 0)
112+
public function stop($code = 0): void
113113
{
114114
exit((int)$code);
115115
}
@@ -172,7 +172,7 @@ protected function handleException(\Throwable $e): int
172172
* @param string $description
173173
* @throws \InvalidArgumentException
174174
*/
175-
public function addCommand(string $command, callable $handler, string $description = '')
175+
public function addCommand(string $command, callable $handler, string $description = ''): void
176176
{
177177
if (!$command || !$handler) {
178178
throw new \InvalidArgumentException('Invalid arguments');
@@ -186,7 +186,7 @@ public function addCommand(string $command, callable $handler, string $descripti
186186
* @param array $commands
187187
* @throws \InvalidArgumentException
188188
*/
189-
public function commands(array $commands)
189+
public function commands(array $commands): void
190190
{
191191
foreach ($commands as $command => $handler) {
192192
$des = '';
@@ -208,7 +208,7 @@ public function commands(array $commands)
208208
/**
209209
* @param string $err
210210
*/
211-
public function displayHelp(string $err = '')
211+
public function displayHelp(string $err = ''): void
212212
{
213213
if ($err) {
214214
echo Color::render("<red>ERROR</red>: $err\n\n");
@@ -263,7 +263,7 @@ public function getArgs(): array
263263
/**
264264
* @param array $args
265265
*/
266-
public function setArgs(array $args)
266+
public function setArgs(array $args): void
267267
{
268268
$this->args = $args;
269269
}
@@ -279,7 +279,7 @@ public function getOpts(): array
279279
/**
280280
* @param array $opts
281281
*/
282-
public function setOpts(array $opts)
282+
public function setOpts(array $opts): void
283283
{
284284
$this->opts = $opts;
285285
}
@@ -295,7 +295,7 @@ public function getScript(): string
295295
/**
296296
* @param string $script
297297
*/
298-
public function setScript(string $script)
298+
public function setScript(string $script): void
299299
{
300300
$this->script = $script;
301301
}
@@ -311,7 +311,7 @@ public function getCommand(): string
311311
/**
312312
* @param string $command
313313
*/
314-
public function setCommand(string $command)
314+
public function setCommand(string $command): void
315315
{
316316
$this->command = $command;
317317
}

src/Cli.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static function read($message = null, $nl = false): string
3838
* @param bool $nl
3939
* @param bool $quit
4040
*/
41-
public static function write($messages, $nl = true, $quit = false)
41+
public static function write($messages, $nl = true, $quit = false): void
4242
{
4343
if (\is_array($messages)) {
4444
$messages = implode($nl ? \PHP_EOL : '', $messages);
@@ -53,7 +53,7 @@ public static function write($messages, $nl = true, $quit = false)
5353
* @param bool $nl
5454
* @param bool|int $quit
5555
*/
56-
public static function stdout(string $message, $nl = true, $quit = false)
56+
public static function stdout(string $message, $nl = true, $quit = false): void
5757
{
5858
fwrite(\STDOUT, $message . ($nl ? \PHP_EOL : ''));
5959
fflush(\STDOUT);
@@ -70,7 +70,7 @@ public static function stdout(string $message, $nl = true, $quit = false)
7070
* @param bool $nl
7171
* @param bool|int $quit
7272
*/
73-
public static function stderr(string $message, $nl = true, $quit = -1)
73+
public static function stderr(string $message, $nl = true, $quit = -1): void
7474
{
7575
fwrite(\STDERR, self::color('[ERROR] ', 'red') . $message . ($nl ? PHP_EOL : ''));
7676
fflush(\STDOUT);

src/Console.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Console extends Cli
3636
* 'coId' => 12,
3737
* ]
3838
*/
39-
public static function log(string $msg, array $data = [], string $type = 'info', array $opts = [])
39+
public static function log(string $msg, array $data = [], string $type = 'info', array $opts = []): void
4040
{
4141
if (isset(self::LOG_LEVEL2TAG[$type])) {
4242
$type = ColorTag::add(\strtoupper($type), self::LOG_LEVEL2TAG[$type]);

src/Download.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class Download
3535
* @param string $type
3636
* @return Download
3737
*/
38-
public static function create(string $url, string $saveAs = '', string $type = self::PROGRESS_TEXT)
38+
public static function create(string $url, string $saveAs = '', string $type = self::PROGRESS_TEXT): Download
3939
{
4040
return new self($url, $saveAs, $type);
4141
}
@@ -122,7 +122,7 @@ public function start(): self
122122
* @param int $transferredBytes Have been transferred bytes
123123
* @param int $maxBytes Target max length bytes
124124
*/
125-
public function progressShow($notifyCode, $severity, $message, $messageCode, $transferredBytes, $maxBytes)
125+
public function progressShow($notifyCode, $severity, $message, $messageCode, $transferredBytes, $maxBytes): void
126126
{
127127
$msg = '';
128128

@@ -205,7 +205,7 @@ public function getShowType(): string
205205
/**
206206
* @param string $showType
207207
*/
208-
public function setShowType(string $showType)
208+
public function setShowType(string $showType): void
209209
{
210210
$this->showType = $showType;
211211
}
@@ -221,7 +221,7 @@ public function getUrl(): string
221221
/**
222222
* @param string $url
223223
*/
224-
public function setUrl(string $url)
224+
public function setUrl(string $url): void
225225
{
226226
$this->url = \trim($url);
227227
}
@@ -237,7 +237,7 @@ public function getSaveAs(): string
237237
/**
238238
* @param string $saveAs
239239
*/
240-
public function setSaveAs(string $saveAs)
240+
public function setSaveAs(string $saveAs): void
241241
{
242242
$this->saveAs = \trim($saveAs);
243243
}

src/Flags.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public static function simpleParseArgv(array $argv): array
3636
}
3737

3838
if (\strpos($value, '=')) {
39-
list($n, $v) = \explode('=', $value);
39+
[$n, $v] = \explode('=', $value);
4040
$opts[$n] = $v;
4141
} else {
4242
$opts[$value] = true;
4343
}
4444
} elseif (\strpos($value, '=')) {
45-
list($n, $v) = \explode('=', $value);
45+
[$n, $v] = \explode('=', $value);
4646
$args[$n] = $v;
4747
} else {
4848
$args[] = $value;
@@ -122,12 +122,12 @@ public static function parseArgv(array $params, array $config = []): array
122122

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

128128
// short-opt: value specified inline (-<opt>=<value>)
129129
} elseif (isset($option{1}) && $option{1} === '=') {
130-
list($option, $value) = \explode('=', $option, 2);
130+
[$option, $value] = \explode('=', $option, 2);
131131
}
132132

133133
// check if next parameter is a descriptor or a value
@@ -170,7 +170,7 @@ public static function parseArgv(array $params, array $config = []): array
170170

171171
// value specified inline (<arg>=<value>)
172172
if (\strpos($p, '=') !== false) {
173-
list($name, $value) = \explode('=', $p, 2);
173+
[$name, $value] = \explode('=', $p, 2);
174174
$args[$name] = self::filterBool($value);
175175
} else {
176176
$args[] = $p;
@@ -232,7 +232,7 @@ public static function parseArray(array $params): array
232232
* @todo ...
233233
* @param string $string
234234
*/
235-
public static function parseString(string $string)
235+
public static function parseString(string $string): void
236236
{
237237

238238
}

src/Highlighter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private function colorLines(array $tokenLines): array
250250

251251
foreach ($tokenLines as $lineCount => $tokenLine) {
252252
$line = '';
253-
foreach ($tokenLine as list($tokenType, $tokenValue)) {
253+
foreach ($tokenLine as [$tokenType, $tokenValue]) {
254254
$style = $this->defaultTheme[$tokenType];
255255

256256
if (Color::hasStyle($style)) {
@@ -308,7 +308,7 @@ public function getDefaultTheme(): array
308308
/**
309309
* @param array $defaultTheme
310310
*/
311-
public function setDefaultTheme(array $defaultTheme)
311+
public function setDefaultTheme(array $defaultTheme): void
312312
{
313313
$this->defaultTheme = \array_merge($this->defaultTheme, $defaultTheme);
314314
}

src/Terminal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static function build($format, $type = 'm'): string
157157
public function cursor($typeName, $arg1 = 1, $arg2 = null): self
158158
{
159159
if (!isset(self::$ctrlCursorCodes[$typeName])) {
160-
Cli::stderr("The [$typeName] is not supported cursor control.", true);
160+
Cli::stderr("The [$typeName] is not supported cursor control.");
161161
}
162162

163163
$code = self::$ctrlCursorCodes[$typeName];
@@ -208,7 +208,7 @@ public function screen(string $typeName, $arg = null): self
208208
return $this;
209209
}
210210

211-
public function reset()
211+
public function reset(): void
212212
{
213213
echo self::END_CHAR;
214214
}

test/ColorTagTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
class ColorTagTest extends TestCase
1919
{
20-
public function testStrip()
20+
public function testStrip(): void
2121
{
2222
$text = ColorTag::strip('<tag>text</tag>');
2323
$this->assertSame('text', $text);
@@ -27,7 +27,7 @@ public function testStrip()
2727
$this->assertSame('<tag>text<tag>', $text);
2828
}
2929

30-
public function testWrap()
30+
public function testWrap(): void
3131
{
3232
$text = ColorTag::wrap('text', 'tag');
3333
$this->assertSame('<tag>text</tag>', $text);
@@ -39,7 +39,7 @@ public function testWrap()
3939
$this->assertSame('', $text);
4040
}
4141

42-
public function testExists()
42+
public function testExists(): void
4343
{
4444
$this->assertTrue(ColorTag::exists('<tag>text</tag>'));
4545
$this->assertFalse(ColorTag::exists('text'));

0 commit comments

Comments
 (0)