Skip to content

Commit 0c2e734

Browse files
committed
breaking: migreate to php 8.0+ syntax
1 parent c1e9e0d commit 0c2e734

29 files changed

+357
-357
lines changed

Diff for: .github/workflows/php.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ jobs:
1515
strategy:
1616
fail-fast: true
1717
matrix:
18-
php: [7.3, 7.4, 8.0]
18+
php: [8.0, 8.1]
1919
os: [ubuntu-latest, macOS-latest] # windows-latest,
20-
include:
21-
- os: 'ubuntu-latest'
22-
php: '7.2'
23-
phpunit: '8.5.13'
24-
- os: 'ubuntu-latest'
25-
php: '7.1'
26-
phpunit: '7.5.20'
20+
# include:
21+
# - os: 'ubuntu-latest'
22+
# php: '7.2'
23+
# phpunit: '8.5.13'
24+
# - os: 'ubuntu-latest'
25+
# php: '7.1'
26+
# phpunit: '7.5.20'
2727

2828
steps:
2929
- name: Checkout

Diff for: .github/workflows/release.yml

+15-16
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,20 @@ jobs:
4242
echo "release tag: ${tag1}"
4343
composer install --no-progress
4444
45-
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
46-
# Docs: https://getcomposer.org/doc/articles/scripts.md
47-
48-
# - name: Build phar and send to github assets
49-
# run: |
50-
# echo $RELEASE_TAG
51-
# echo $RELEASE_NAME
52-
# php -d phar.readonly=0 bin/kite phar:pack -o kite-${RELEASE_TAG}.phar --no-progress
53-
# php kite-${RELEASE_TAG}.phar -V
54-
55-
# https://github.com/actions/create-release
56-
- uses: meeDamian/[email protected]
45+
- name: Generate changelog file
46+
id: changelog
47+
run: |
48+
wget -c -q https://github.com/inhere/kite/releases/latest/download/kite.phar
49+
php kite.phar git cl prev last --style gh-release --no-merges --fetch-tags --unshallow --file changelog.md
50+
cat changelog.md
51+
52+
# https://github.com/softprops/action-gh-release
53+
- name: Create release and upload assets
54+
uses: softprops/action-gh-release@v1
5755
with:
58-
gzip: false
59-
token: ${{ secrets.GITHUB_TOKEN }}
60-
tag: ${{ env.RELEASE_TAG }}
6156
name: ${{ env.RELEASE_TAG }}
62-
# files: kite-${{ env.RELEASE_TAG }}.phar
57+
tag_name: ${{ env.RELEASE_TAG }}
58+
body_path: changelog.md
59+
# files: kite-${{ env.RELEASE_TAG }}.phar
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Terminal::clearScreen();
8181
> This is inspire `jakub-onderka/php-console-highlighter`
8282
8383
```php
84-
use Toolkit\Cli\Highlighter;
84+
use Toolkit\Cli\Util\Highlighter;
8585

8686
// this is an comment
8787
$rendered = Highlighter::create()->highlight(file_get_contents(__FILE__));

Diff for: composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
}
2020
],
2121
"require": {
22-
"php": ">7.1.0"
22+
"php": ">8.0.0"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
2625
"ext-posix": "*",
2726
"ext-readline": "*"
2827
},

Diff for: example/readline/cb_handler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function handler_read_demo(int $count, string $prompt = null): string
1818

1919
// 初始化一个 readline 回调接口,然后终端输出提示信息并立即返回
2020
// TIP: 第二次调用这个函数不需要移除上一个回调接口,这个函数将自动覆盖旧的接口
21-
readline_callback_handler_install($prompt ?? " \e[D", function ($input) use (&$prev) {
21+
readline_callback_handler_install($prompt ?? " \e[D", static function ($input) use (&$prev) {
2222
echo "Input is: $input\n";
2323
$prev .= $input . '|';
2424
});

Diff for: example/term_move.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class TermMove {
44

5-
const KEYS = [
5+
public const KEYS = [
66
10 => 'enter',
77
127 => 'backspace',
88
65 => 'up',
@@ -50,7 +50,7 @@ public function char() : string
5050
return $c;
5151
}
5252

53-
readline_callback_handler_install('', function() {});
53+
readline_callback_handler_install('', static function() {});
5454
// $c = $this->read(1);
5555
// $c = fread(STDIN, 4);
5656
$c = stream_get_contents(STDIN, 4);

Diff for: src/App.php

+28-27
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@
3737
* Class App - A lite CLI Application
3838
*
3939
* @package Inhere\Console
40+
* @deprecated please use package: toolkit/pflag
4041
*/
4142
class App
4243
{
43-
/** @var self */
44-
public static $global;
44+
/** @var self|null */
45+
public static ?self $global = null;
4546

4647
private const COMMAND_CONFIG = [
4748
'desc' => '',
@@ -50,12 +51,12 @@ class App
5051
];
5152

5253
/** @var string Current dir */
53-
private $pwd;
54+
private string $pwd;
5455

5556
/**
5657
* @var array
5758
*/
58-
protected $params = [
59+
protected array $params = [
5960
'name' => 'My application',
6061
'desc' => 'My command line application',
6162
'version' => '0.2.1'
@@ -64,37 +65,37 @@ class App
6465
/**
6566
* @var array Parsed from `arg0 name=val var2=val2`
6667
*/
67-
private $args;
68+
private mixed $args;
6869

6970
/**
7071
* @var array Parsed from `--name=val --var2=val2 -d`
7172
*/
72-
private $opts;
73+
private mixed $opts;
7374

7475
/**
7576
* @var string
7677
*/
77-
private $script;
78+
private mixed $script;
7879

7980
/**
8081
* @var string
8182
*/
82-
private $command = '';
83+
private string $command = '';
8384

8485
/**
8586
* @var array User add commands
8687
*/
87-
private $commands = [];
88+
private array $commands = [];
8889

8990
/**
9091
* @var array Command messages for the commands
9192
*/
92-
private $messages = [];
93+
private array $messages = [];
9394

9495
/**
9596
* @var int
9697
*/
97-
private $keyWidth = 12;
98+
private int $keyWidth = 12;
9899

99100
/**
100101
* @return static
@@ -233,7 +234,7 @@ public function stop(int $code = 0): void
233234
* @return mixed
234235
* @throws InvalidArgumentException
235236
*/
236-
public function runHandler(string $command, $handler)
237+
public function runHandler(string $command, mixed $handler): mixed
237238
{
238239
if (is_string($handler)) {
239240
// function name
@@ -315,19 +316,19 @@ public function addByConfig(callable $handler, array $config): void
315316
/**
316317
* @param string $command
317318
* @param callable $handler
318-
* @param null|array|string $config
319+
* @param array|string|null $config
319320
*/
320-
public function add(string $command, callable $handler, $config = null): void
321+
public function add(string $command, callable $handler, array|string $config = null): void
321322
{
322323
$this->addCommand($command, $handler, $config);
323324
}
324325

325326
/**
326327
* @param string $command
327328
* @param callable $handler
328-
* @param null|array|string $config
329+
* @param array|string|null $config
329330
*/
330-
public function addCommand(string $command, callable $handler, $config = null): void
331+
public function addCommand(string $command, callable $handler, array|string $config = null): void
331332
{
332333
if (!$command) {
333334
throw new InvalidArgumentException('Invalid arguments for add command');
@@ -463,45 +464,45 @@ public function displayCommandHelp(string $name): void
463464
}
464465

465466
/**
466-
* @param string|int $name
467-
* @param mixed $default
467+
* @param int|string $name
468+
* @param mixed|null $default
468469
*
469470
* @return mixed|null
470471
*/
471-
public function getArg($name, $default = null)
472+
public function getArg(int|string $name, mixed $default = null): mixed
472473
{
473474
return $this->args[$name] ?? $default;
474475
}
475476

476477
/**
477-
* @param string|int $name
478+
* @param int|string $name
478479
* @param int $default
479480
*
480481
* @return int
481482
*/
482-
public function getIntArg($name, int $default = 0): int
483+
public function getIntArg(int|string $name, int $default = 0): int
483484
{
484485
return (int)$this->getArg($name, $default);
485486
}
486487

487488
/**
488-
* @param string|int $name
489+
* @param int|string $name
489490
* @param string $default
490491
*
491492
* @return string
492493
*/
493-
public function getStrArg($name, string $default = ''): string
494+
public function getStrArg(int|string $name, string $default = ''): string
494495
{
495496
return (string)$this->getArg($name, $default);
496497
}
497498

498499
/**
499500
* @param string $name
500-
* @param mixed $default
501+
* @param mixed|null $default
501502
*
502503
* @return mixed|null
503504
*/
504-
public function getOpt(string $name, $default = null)
505+
public function getOpt(string $name, mixed $default = null): mixed
505506
{
506507
return $this->opts[$name] ?? $default;
507508
}
@@ -688,7 +689,7 @@ public function setMetas(array $params): void
688689
*
689690
* @return mixed|string|null
690691
*/
691-
public function getParam(string $key, $default = null)
692+
public function getParam(string $key, $default = null): mixed
692693
{
693694
return $this->params[$key] ?? $default;
694695
}
@@ -697,7 +698,7 @@ public function getParam(string $key, $default = null)
697698
* @param string $key
698699
* @param mixed $val
699700
*/
700-
public function setParam(string $key, $val): void
701+
public function setParam(string $key, mixed $val): void
701702
{
702703
$this->params[$key] = $val;
703704
}

Diff for: src/Cli.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use function is_numeric;
2525
use function json_encode;
2626
use function preg_replace;
27-
use function strpos;
27+
use function stream_isatty;
2828
use function strtoupper;
2929
use function trim;
3030
use const DIRECTORY_SEPARATOR;
@@ -87,10 +87,10 @@ public static function __callStatic(string $method, array $args)
8787
/**
8888
* Print colored message to STDOUT
8989
*
90-
* @param string|array $message
91-
* @param string|array|null $style
90+
* @param array|string $message
91+
* @param array|string $style
9292
*/
93-
public static function colored($message, $style = 'info'): void
93+
public static function colored(array|string $message, array|string $style = 'info'): void
9494
{
9595
$str = is_array($message) ? implode(' ', $message) : (string)$message;
9696

@@ -110,12 +110,12 @@ public static function style(): Style
110110
}
111111

112112
/**
113-
* @param string $text
114-
* @param string|int|array|null $style
113+
* @param string $text
114+
* @param array|string|null $style
115115
*
116116
* @return string
117117
*/
118-
public static function color(string $text, $style = null): string
118+
public static function color(string $text, array|string $style = null): string
119119
{
120120
return Color::render($text, $style);
121121
}
@@ -152,7 +152,7 @@ public static function clog(string $msg, array $data = [], string $type = 'info'
152152
$userOpts = [];
153153

154154
foreach ($opts as $n => $v) {
155-
if (is_numeric($n) || strpos($n, '_') === 0) {
155+
if (is_numeric($n) || str_starts_with($n, '_')) {
156156
$userOpts[] = "[$v]";
157157
} else {
158158
$userOpts[] = "[$n:$v]";
@@ -225,7 +225,7 @@ public static function isSupportColor(): bool
225225
*/
226226
public static function isSupport256Color(): bool
227227
{
228-
return DIRECTORY_SEPARATOR === '/' && strpos(getenv('TERM'), '256color') !== false;
228+
return DIRECTORY_SEPARATOR === '/' && str_contains(getenv('TERM'), '256color');
229229
}
230230

231231
/**
@@ -247,11 +247,11 @@ public static function isAnsiSupport(): bool
247247
*
248248
* @return boolean
249249
*/
250-
public static function isInteractive($fileDescriptor): bool
250+
public static function isInteractive(mixed $fileDescriptor): bool
251251
{
252252
// PHP 7 >= 7.2.0
253253
if (function_exists('stream_isatty')) {
254-
return \stream_isatty($fileDescriptor);
254+
return stream_isatty($fileDescriptor);
255255
}
256256

257257
return function_exists('posix_isatty') && @posix_isatty($fileDescriptor);

0 commit comments

Comments
 (0)