Skip to content

Commit 3d25279

Browse files
committed
chore: run php-cs-fixer for the .
1 parent 24482ff commit 3d25279

27 files changed

+171
-51
lines changed

Diff for: example/keyboard.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
3-
* https://www.sitepoint.com/howd-they-do-it-phpsnake-detecting-keypresses/
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
48
*/
59

6-
function test_run()
10+
function test_run(): void
711
{
8-
echo "Hello, I am snake!";
12+
echo 'Hello, I am snake!';
913

1014
system('stty cbreak -echo');
1115
$stdin = fopen('php://stdin', 'rb');
@@ -20,4 +24,3 @@ function test_run()
2024
require dirname(__DIR__) . '/test/bootstrap.php';
2125

2226
test_run();
23-

Diff for: example/readline/cb_handler.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
3-
* https://www.php.net/manual/zh/function.readline-callback-handler-install.php
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
48
*/
59

610
require dirname(__DIR__) . '/../test/bootstrap.php';
@@ -18,7 +22,7 @@ function handler_read_demo(int $count, string $prompt = null): string
1822

1923
// 初始化一个 readline 回调接口,然后终端输出提示信息并立即返回
2024
// TIP: 第二次调用这个函数不需要移除上一个回调接口,这个函数将自动覆盖旧的接口
21-
readline_callback_handler_install($prompt ?? " \e[D", static function ($input) use (&$prev) {
25+
readline_callback_handler_install($prompt ?? " \e[D", static function ($input) use (&$prev): void {
2226
echo "Input is: $input\n";
2327
$prev .= $input . '|';
2428
});
@@ -48,4 +52,4 @@ function handler_read_demo(int $count, string $prompt = null): string
4852

4953
$str = handler_read_demo(20, 'TEST > ');
5054

51-
echo "str: $str";
55+
echo "str: $str";

Diff for: example/readline/cb_handler2.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
3-
* https://www.jb51.net/article/212496.htm
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
48
*/
59

610
use Toolkit\Cli\Util\Readline;
711

812
require dirname(__DIR__) . '/../test/bootstrap.php';
913

1014
// 输出的内容进入这个回调函数中
11-
function rl_callback($ret)
15+
function rl_callback($ret): void
1216
{
1317
global $c, $prompting;
1418

@@ -84,4 +88,4 @@ function rl_callback($ret)
8488
// [7] => H
8589
// [8] => I
8690
// [9] => J
87-
// )
91+
// )

Diff for: example/readline/complete.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
3-
* @link https://www.php.net/manual/zh/function.readline-completion-function.php
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
48
*/
59

610
require dirname(__DIR__) . '/../test/bootstrap.php';
@@ -55,13 +59,13 @@ function your_callback($input, $index): array
5559

5660
// 使用 Tab 键测试一下吧
5761
// $line = \Toolkit\Cli\Cli::readln('please input> ');
58-
$line = trim(readline("please input> "));
62+
$line = trim(readline('please input> '));
5963
if (!empty($line)) {
6064
readline_add_history($line);
6165
}
6266

6367
echo $line, PHP_EOL; // 当前输入的命令信息
6468
// 如果命令是 exit 或者 quit ,就退出程序执行
65-
if($line === 'exit' || $line === 'quit'){
69+
if ($line === 'exit' || $line === 'quit') {
6670
exit('bye');
6771
}

Diff for: example/readline/readline.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
8+
*/
29

310
require dirname(__DIR__) . '/../test/bootstrap.php';
411

5-
$line = readline("command:"); // 读取命令行交互信息
12+
$line = readline('command:'); // 读取命令行交互信息
613
if (!empty($line)) {
714
readline_add_history($line); // 需要手动加入到命令历史记录中
815
}
916
echo $line, PHP_EOL; // aaa
1017

11-
$line = readline("command:");
18+
$line = readline('command:');
1219
if (!empty($line)) {
1320
readline_add_history($line);
1421
}
@@ -42,4 +49,4 @@
4249
// [library_version] => 7.0
4350
// [readline_name] => other
4451
// [attempted_completion_over] => 0
45-
// )
52+
// )

Diff for: example/term_move.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
<?php
2-
3-
class TermMove {
1+
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
8+
*/
49

10+
class TermMove
11+
{
512
public const KEYS = [
613
10 => 'enter',
714
127 => 'backspace',
@@ -44,13 +51,14 @@ public function char() : string
4451
{
4552
// return fread(STDIN, 4);
4653

47-
if (DIRECTORY_SEPARATOR === "\\") {
54+
if (DIRECTORY_SEPARATOR === '\\') {
4855
$c = stream_get_contents(STDIN, 1);
4956

5057
return $c;
5158
}
5259

53-
readline_callback_handler_install('', static function() {});
60+
readline_callback_handler_install('', static function (): void {
61+
});
5462
// $c = $this->read(1);
5563
// $c = fread(STDIN, 4);
5664
$c = stream_get_contents(STDIN, 4);
@@ -64,6 +72,6 @@ public function char() : string
6472

6573
$tm = new TermMove();
6674

67-
echo "please input:";
75+
echo 'please input:';
6876
$c = $tm->readChar();
6977
echo "CHAR: $c\n";

Diff for: src/Cli.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Cli
6565
* @param string $method {@see Color::STYLES}
6666
* @param array $args
6767
*/
68-
public static function __callStatic(string $method, array $args)
68+
public static function __callStatic(string $method, array $args): void
6969
{
7070
if ($method === 'alert') {
7171
Alert::global()->withStyle($args[1] ?? '')->println($args[0]);
@@ -172,7 +172,7 @@ public static function clog(string $msg, array $data = [], string $type = 'info'
172172
$optString = $userOpts ? ' ' . implode(' ', $userOpts) : '';
173173
$dataString = $data ? PHP_EOL . json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) : '';
174174

175-
$msg = sprintf("%s [%s]%s %s %s", date('Y/m/d H:i:s'), $type, $optString, trim($msg), $dataString);
175+
$msg = sprintf('%s [%s]%s %s %s', date('Y/m/d H:i:s'), $type, $optString, trim($msg), $dataString);
176176
self::writeln($msg, false, $writeOpt);
177177
}
178178

Diff for: src/Color.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ public static function render(string $text, array|string $style = null): string
274274
if (is_string($style)) {
275275
$color = self::STYLES[$style] ?? '';
276276

277-
// custom style: [self::FG_GREEN, self::BG_WHITE, self::UNDERSCORE]
277+
// custom style: [self::FG_GREEN, self::BG_WHITE, self::UNDERSCORE]
278278
} elseif (is_array($style)) {
279279
$color = implode(';', $style);
280280

281-
// user color tag: <info>message</info>
281+
// user color tag: <info>message</info>
282282
} elseif (strpos($text, '</') > 0) {
283283
return self::parseTag($text);
284284
}

Diff for: src/Color/ANSICode.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
8+
*/
29

310
namespace Toolkit\Cli\Color;
411

@@ -106,5 +113,4 @@ abstract class ANSICode
106113
public const REVERSE = 7; // 颠倒的 交换背景色与前景色
107114

108115
public const CONCEALED = 8; // 隐匿的
109-
110-
}
116+
}

Diff for: src/Color/Alert.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php declare(strict_types=1);
2-
2+
/**
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
8+
*/
39

410
namespace Toolkit\Cli\Color;
511

Diff for: src/Color/Prompt.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php declare(strict_types=1);
2-
2+
/**
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
8+
*/
39

410
namespace Toolkit\Cli\Color;
511

@@ -129,4 +135,4 @@ public function setTitle(string $title): self
129135
$this->title = $title;
130136
return $this;
131137
}
132-
}
138+
}

Diff for: src/Helper/CliHelper.php

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
8+
*/
29

310
namespace Toolkit\Cli\Helper;
411

@@ -17,6 +24,7 @@ class CliHelper
1724
{
1825
// These words will be as a Boolean value
1926
public const TRUE_WORDS = '|on|yes|true|';
27+
2028
public const FALSE_WORDS = '|off|no|false|';
2129

2230
/**

Diff for: src/Style.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public function format(string $text): string
224224
$text = ColorTag::replaceColor($text, $key, $matches[2][$i], (string)$this->styles[$key]);
225225
} elseif (isset(Color::STYLES[$key])) {
226226
$text = ColorTag::replaceColor($text, $key, $matches[2][$i], Color::STYLES[$key]);
227-
/** Custom style format @see ColorCode::fromString() */
227+
/** Custom style format @see ColorCode::fromString() */
228228
} elseif (strpos($key, '=')) {
229229
$text = ColorTag::replaceColor($text, $key, $matches[2][$i], (string)ColorCode::fromString($key));
230230
}

Diff for: src/Traits/WriteMessageTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function echo(...$args): void
5454
*/
5555
public function echoln(...$args): void
5656
{
57-
echo (count($args) > 1 ? implode(' ', $args) : $args[0]), PHP_EOL;
57+
echo(count($args) > 1 ? implode(' ', $args) : $args[0]), PHP_EOL;
5858
}
5959

6060
/**

Diff for: src/Util/CliLogger.php

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
8+
*/
29

310
namespace Toolkit\Cli\Util;
411

@@ -26,12 +33,19 @@
2633
class CliLogger // implements LoggerInterface
2734
{
2835
public const EMERGENCY = 'emergency';
36+
2937
public const ALERT = 'alert';
38+
3039
public const CRITICAL = 'critical';
40+
3141
public const ERROR = 'error';
42+
3243
public const WARNING = 'warning';
44+
3345
public const NOTICE = 'notice';
46+
3447
public const INFO = 'info';
48+
3549
public const DEBUG = 'debug';
3650

3751
public const LEVEL2COLOR = [

Diff for: src/Util/Clog.php

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
8+
*/
29

310
namespace Toolkit\Cli\Util;
411

Diff for: src/Util/Download.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function start(): self
152152
Cli::write("\nDone!");
153153
} else {
154154
$err = error_get_last();
155-
Cli::stderr("\nErr.rrr..orr...\n {$err['message']}\n", true, true,-1);
155+
Cli::stderr("\nErr.rrr..orr...\n {$err['message']}\n", true, true, -1);
156156
}
157157

158158
// close resource

Diff for: src/Util/Keyboard.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php declare(strict_types=1);
2-
2+
/**
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
8+
*/
39

410
namespace Toolkit\Cli\Util;
511

@@ -34,5 +40,4 @@ public static function new(): self
3440
{
3541
return new self;
3642
}
37-
38-
}
43+
}

Diff for: src/Util/Readline.php

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php declare(strict_types=1);
2+
/**
3+
* This file is part of toolkit/cli-utils.
4+
*
5+
* @link https://github.com/php-toolkit/cli-utils
6+
* @author https://github.com/inhere
7+
* @license MIT
8+
*/
29

310
namespace Toolkit\Cli\Util;
411

0 commit comments

Comments
 (0)