Skip to content

Commit fe905f1

Browse files
authored
[3.0] 更新开发工具集 (#594)
* Update: phpstan 1.10.39 * Update: core 规则更新 * Update: 组件规则更新 * Update: 重构 phpstan 启动代码 * Fix * Update: .gitattributes * Update: 调整目录结构 * Fix * Update: 修复一些错误报告 * Update: 重新生成 core 基线 * Update: 应用 php-cs-fixer 修复 * Update: rector 0.18.5 * Update: 更新代码风格规范 * Update: 应用 rector 的更改到核心 * Update: 格式化代码 * Update: 修复代码分析 * Update: 修复代码风格 * Update: 应用 rector 的更改到组件 * Update: 修复代码风格 * Update: 更新工具脚本 * Update: 修复代码风格 * Update: 使工作流能在推送新提交时自动取消前一个 * Update: 选择更合适的唯一组合
1 parent 28cf2c7 commit fe905f1

File tree

404 files changed

+2388
-2902
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

404 files changed

+2388
-2902
lines changed

Diff for: .gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
/.markdownlint.json export-ignore
1616
/.php-cs-fixer.php export-ignore
1717
/package.json export-ignore
18+
/phpstan-baseline export-ignore
1819
/phpstan-components.neon export-ignore
1920
/phpstan.neon export-ignore
20-
/phpstan.sh export-ignore
2121
/rector.php export-ignore
2222
/rector.sh export-ignore

Diff for: .github/workflows/ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ on:
1212
- "README.md"
1313
pull_request:
1414

15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
17+
cancel-in-progress: true
18+
1519
jobs:
1620
ci:
1721
name: Linux Swoole-${{ matrix.swoole.version }} RoadRunner-${{ matrix.roadrunner }}

Diff for: .github/workflows/codecov.yml

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ on:
1212
- "README.md"
1313
pull_request:
1414

15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
17+
cancel-in-progress: true
18+
1519
jobs:
1620
test:
1721
runs-on: ubuntu-latest

Diff for: .github/workflows/phpcs.yml

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
- "README.md"
1212
pull_request:
1313

14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
16+
cancel-in-progress: true
17+
1418
jobs:
1519
tests:
1620
runs-on: ubuntu-20.04

Diff for: .github/workflows/phpstan.yml

+27-23
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
- "README.md"
1212
pull_request:
1313

14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
16+
cancel-in-progress: true
17+
1418
jobs:
1519
tests:
1620
runs-on: ubuntu-20.04
@@ -40,114 +44,114 @@ jobs:
4044
- name: Analyse core
4145
if: ${{ env.test_prepared && always() }}
4246
run: |
43-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G
47+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh core
4448
4549
- name: Analyse access-control
4650
if: ${{ env.test_prepared && always() }}
4751
run: |
48-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/access-control/vendor/autoload.php src/Components/access-control
52+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh access-control
4953
5054
- name: Analyse amqp
5155
if: ${{ env.test_prepared && always() }}
5256
run: |
53-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/amqp/vendor/autoload.php src/Components/amqp
57+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh amqp
5458
5559
- name: Analyse apidoc
5660
if: ${{ env.test_prepared && always() }}
5761
run: |
58-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/apidoc/vendor/autoload.php src/Components/apidoc
62+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh apidoc
5963
6064
- name: Analyse fpm
6165
if: ${{ env.test_prepared && always() }}
6266
run: |
63-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/fpm/vendor/autoload.php src/Components/fpm
67+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh fpm
6468
6569
- name: Analyse grpc
6670
if: ${{ env.test_prepared && always() }}
6771
run: |
68-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/grpc/vendor/autoload.php src/Components/grpc
72+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh grpc
6973
7074
- name: Analyse jwt
7175
if: ${{ env.test_prepared && always() }}
7276
run: |
73-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/jwt/vendor/autoload.php src/Components/jwt
77+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh jwt
7478
7579
- name: Analyse kafka
7680
if: ${{ env.test_prepared && always() }}
7781
run: |
78-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/kafka/vendor/autoload.php src/Components/kafka
82+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh kafka
7983
8084
- name: Analyse mqtt
8185
if: ${{ env.test_prepared && always() }}
8286
run: |
83-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/mqtt/vendor/autoload.php src/Components/mqtt
87+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh mqtt
8488
8589
- name: Analyse pgsql
8690
if: ${{ env.test_prepared && always() }}
8791
run: |
88-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/pgsql/vendor/autoload.php src/Components/pgsql
92+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh pgsql
8993
9094
- name: Analyse queue
9195
if: ${{ env.test_prepared && always() }}
9296
run: |
93-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/queue/vendor/autoload.php src/Components/queue
97+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh queue
9498
9599
- name: Analyse rate-limit
96100
if: ${{ env.test_prepared && always() }}
97101
run: |
98-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/rate-limit/vendor/autoload.php src/Components/rate-limit
102+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh rate-limit
99103
100104
- name: Analyse roadrunner
101105
if: ${{ env.test_prepared && always() }}
102106
run: |
103-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/roadrunner/vendor/autoload.php src/Components/roadrunner
107+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh roadrunner
104108
105109
- name: Analyse rpc
106110
if: ${{ env.test_prepared && always() }}
107111
run: |
108-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/rpc/vendor/autoload.php src/Components/rpc
112+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh rpc
109113
110114
- name: Analyse shared-memory
111115
if: ${{ env.test_prepared && always() }}
112116
run: |
113-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/shared-memory/vendor/autoload.php src/Components/shared-memory
117+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh shared-memory
114118
115119
- name: Analyse smarty
116120
if: ${{ env.test_prepared && always() }}
117121
run: |
118-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/smarty/vendor/autoload.php src/Components/smarty
122+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh smarty
119123
120124
- name: Analyse snowflake
121125
if: ${{ env.test_prepared && always() }}
122126
run: |
123-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/snowflake/vendor/autoload.php src/Components/snowflake
127+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh snowflake
124128
125129
- name: Analyse swoole
126130
if: ${{ env.test_prepared && always() }}
127131
run: |
128-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/swoole/vendor/autoload.php src/Components/swoole
132+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh swoole
129133
130134
- name: Analyse swoole-tracker
131135
if: ${{ env.test_prepared && always() }}
132136
run: |
133-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/swoole-tracker/vendor/autoload.php src/Components/swoole-tracker
137+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh swoole-tracker
134138
135139
- name: Analyse workerman
136140
if: ${{ env.test_prepared && always() }}
137141
run: |
138-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/workerman/vendor/autoload.php src/Components/workerman
142+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh workerman
139143
140144
- name: Analyse workerman-gateway
141145
if: ${{ env.test_prepared && always() }}
142146
run: |
143-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/workerman-gateway/vendor/autoload.php src/Components/workerman-gateway
147+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh workerman-gateway
144148
145149
- name: Analyse macro
146150
if: ${{ env.test_prepared && always() }}
147151
run: |
148-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/macro/vendor/autoload.php src/Components/macro
152+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh macro
149153
150154
- name: Analyse phar
151155
if: ${{ env.test_prepared && always() }}
152156
run: |
153-
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G --configuration=phpstan-components.neon --autoload-file=src/Components/phar/vendor/autoload.php src/Components/phar
157+
docker exec ${ENV_SERVICE} ./dev/phpstan.sh phar

Diff for: .github/workflows/rector.yml

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ on:
1111
- "README.md"
1212
pull_request:
1313

14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
16+
cancel-in-progress: true
17+
1418
jobs:
1519
tests:
1620
runs-on: ubuntu-20.04

Diff for: .php-cs-fixer.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
return (new PhpCsFixer\Config())
1111
->setRules([
12-
'@PHP74Migration' => true,
13-
'@PHP74Migration:risky' => true,
12+
'@PHP81Migration' => true,
13+
'@PHP80Migration:risky' => true,
1414
'@Symfony' => true,
1515
'@Symfony:risky' => true,
1616
'@DoctrineAnnotation' => true,
@@ -116,7 +116,6 @@
116116
'return_assignment' => true,
117117
'explicit_string_variable' => true,
118118
'heredoc_to_nowdoc' => true,
119-
'void_return' => false, // BUG:https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/6690
120119
// Symfony 冲突
121120
'braces_position' => [
122121
'control_structures_opening_brace' => 'next_line_unless_newline_at_signature_end',
@@ -128,8 +127,6 @@
128127
'remove_inheritdoc' => false,
129128
],
130129
'no_null_property_initialization' => false,
131-
// 当支持 php>=8.0 后改配置可以移除
132-
'get_class_to_class_keyword' => false,
133130
])
134131
->setRiskyAllowed(true)
135132
->setFinder(

Diff for: composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
"require-dev": {
2626
"composer/semver": "^3.3.2",
2727
"php-cs-fixer/shim": "~3.35.1",
28-
"phpstan/phpstan": "~1.8.0",
28+
"phpstan/phpstan": "~1.10.39",
2929
"phpunit/phpunit": "~9.6",
30-
"rector/rector": "~0.13",
30+
"rector/rector": "~0.18.5",
3131
"symfony/polyfill-uuid": "^1.27",
3232
"yurunsoft/ide-helper": "~1.0",
3333
"yurunsoft/yurun-http": "^5.0.0"

Diff for: dev/Plugin.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function IDEHelper(): void
6363
'--app-namespace=Imi\\\\Dev',
6464
];
6565
$process = self::createProcess($cmd);
66-
$process->run(static function ($type, $buffer) {
66+
$process->run(static function ($type, $buffer): void {
6767
echo $buffer;
6868
});
6969

@@ -105,7 +105,7 @@ protected static function parallel(array $processes, int $max, string $titleTemp
105105
{
106106
++$running;
107107
$output->writeln("[{$title}]");
108-
$process->start(static function ($type, $buffer) {
108+
$process->start(static function ($type, $buffer): void {
109109
echo $buffer;
110110
});
111111
}

Diff for: dev/bootstrap.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ function getRectorConfigCallback(string $path): callable
5252
\Rector\Php71\Rector\FuncCall\CountOnNullRector::class,
5353
\Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector::class,
5454
\Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector::class,
55-
\Rector\Php70\Rector\FuncCall\RandomFunctionRector::class,
55+
56+
// 存在兼容问题
57+
\Rector\Php80\Rector\FunctionLike\MixedTypeRector::class, // todo 给接口参数加了`mixed`但没给实现加类型,导致静态分析报错
58+
\Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector::class, // todo 调整包含默认参的参数顺序,会导致代码被破坏
59+
\Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector::class, // 无法正确处理继承覆盖的情况
5660
]);
5761

5862
$rectorConfig->bootstrapFiles([
@@ -63,7 +67,7 @@ function getRectorConfigCallback(string $path): callable
6367
$path . '/src',
6468
]);
6569

66-
$rectorConfig->sets([LevelSetList::UP_TO_PHP_74]);
70+
$rectorConfig->sets([LevelSetList::UP_TO_PHP_81]);
6771
};
6872
}
6973

@@ -167,7 +171,7 @@ function checkPorts(array $ports, string $host = '127.0.0.1', int $tryCount = 30
167171
if (isCodeCoverage())
168172
{
169173
putenv('IMI_CODE_COVERAGE_NAME=' . getCodeCoverageName());
170-
(static function () {
174+
(static function (): void {
171175
$filter = new Filter();
172176
$filter->includeDirectory(\dirname(__DIR__) . '/src');
173177
$componentsDir = \dirname(__DIR__) . '/src/Components';
@@ -185,7 +189,7 @@ function checkPorts(array $ports, string $host = '127.0.0.1', int $tryCount = 30
185189
$codeCoverage->start('imi');
186190

187191
$stoped = false;
188-
$shutdownCallback = static function () use ($codeCoverage, &$stoped) {
192+
$shutdownCallback = static function () use ($codeCoverage, &$stoped): void {
189193
if (!$stoped)
190194
{
191195
$stoped = true;

Diff for: dev/phpstan.sh

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
3+
__DIR__=$(cd `dirname $0`; pwd)
4+
cd "$__DIR__/.."
5+
__DIR__=$(pwd)
6+
7+
components=(
8+
# "core" 默认不处理
9+
"access-control"
10+
"amqp"
11+
"apidoc"
12+
"fpm"
13+
"grpc"
14+
"jwt"
15+
"kafka"
16+
"mqtt"
17+
"pgsql"
18+
"queue"
19+
"rate-limit"
20+
"roadrunner"
21+
"rpc"
22+
"shared-memory"
23+
"smarty"
24+
"snowflake"
25+
"swoole"
26+
"swoole-tracker"
27+
"workerman"
28+
"workerman-gateway"
29+
"macro"
30+
)
31+
32+
analyze_component() {
33+
component="$1"
34+
gen_baseline="$2"
35+
echo "Analyzing: $component, Generate Baseline: $gen_baseline"
36+
37+
analyse_configuration=""
38+
39+
args=()
40+
args+=("--memory-limit" "1G")
41+
42+
if [ "$component" != "core" ]; then
43+
args+=("--configuration=phpstan-components.neon" "--autoload-file=src/Components/$component/vendor/autoload.php" "src/Components/$component")
44+
fi
45+
46+
if [ "$gen_baseline" == "true" ]; then
47+
args+=("--generate-baseline=./phpstan-baseline/baseline-$component.neon" "--allow-empty-baseline")
48+
fi
49+
50+
echo ./vendor/bin/phpstan analyse "${args[@]}"
51+
52+
PHPSTAN_ANALYSE_COMPONENT_NAME="$component" PHPSTAN_GENERATE_BASELINE="$gen_baseline" ./vendor/bin/phpstan analyse "${args[@]}"
53+
}
54+
55+
use_baseline="false"
56+
input_components=()
57+
58+
while [[ $# -gt 0 ]]; do
59+
case "$1" in
60+
--baseline)
61+
use_baseline="true"
62+
shift
63+
;;
64+
-b)
65+
use_baseline="true"
66+
shift
67+
;;
68+
*)
69+
# 如果不是 --baseline 标志,将参数添加到 components 数组中
70+
input_components+=("$1")
71+
shift
72+
;;
73+
esac
74+
done
75+
76+
if [ ${#input_components[@]} -eq 0 ]; then
77+
# If no arguments are provided, analyze all components
78+
for component in "${components[@]}"; do
79+
analyze_component "$component" "$use_baseline"
80+
done
81+
else
82+
# Analyze the specified components provided as arguments
83+
for component in "${input_components[@]}"; do
84+
if [[ " ${components[@]} " =~ " $component " || "core" == "$component" ]]; then
85+
analyze_component "$component" "$use_baseline"
86+
else
87+
echo "Invalid component name: $component"
88+
fi
89+
done
90+
fi

0 commit comments

Comments
 (0)