Skip to content

Commit

Permalink
[3.0] 更新开发工具集 (#594)
Browse files Browse the repository at this point in the history
* 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: 选择更合适的唯一组合
  • Loading branch information
NHZEX authored Oct 20, 2023
1 parent 28cf2c7 commit fe905f1
Show file tree
Hide file tree
Showing 404 changed files with 2,388 additions and 2,902 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
/.markdownlint.json export-ignore
/.php-cs-fixer.php export-ignore
/package.json export-ignore
/phpstan-baseline export-ignore
/phpstan-components.neon export-ignore
/phpstan.neon export-ignore
/phpstan.sh export-ignore
/rector.php export-ignore
/rector.sh export-ignore
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
- "README.md"
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
ci:
name: Linux Swoole-${{ matrix.swoole.version }} RoadRunner-${{ matrix.roadrunner }}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
- "README.md"
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
- "README.md"
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
tests:
runs-on: ubuntu-20.04
Expand Down
50 changes: 27 additions & 23 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
- "README.md"
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
tests:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -40,114 +44,114 @@ jobs:
- name: Analyse core
if: ${{ env.test_prepared && always() }}
run: |
docker exec ${ENV_SERVICE} ./vendor/bin/phpstan analyse --memory-limit 1G
docker exec ${ENV_SERVICE} ./dev/phpstan.sh core
- name: Analyse access-control
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh access-control
- name: Analyse amqp
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh amqp
- name: Analyse apidoc
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh apidoc
- name: Analyse fpm
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh fpm
- name: Analyse grpc
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh grpc
- name: Analyse jwt
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh jwt
- name: Analyse kafka
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh kafka
- name: Analyse mqtt
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh mqtt
- name: Analyse pgsql
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh pgsql
- name: Analyse queue
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh queue
- name: Analyse rate-limit
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh rate-limit
- name: Analyse roadrunner
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh roadrunner
- name: Analyse rpc
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh rpc
- name: Analyse shared-memory
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh shared-memory
- name: Analyse smarty
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh smarty
- name: Analyse snowflake
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh snowflake
- name: Analyse swoole
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh swoole
- name: Analyse swoole-tracker
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh swoole-tracker
- name: Analyse workerman
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh workerman
- name: Analyse workerman-gateway
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh workerman-gateway
- name: Analyse macro
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh macro
- name: Analyse phar
if: ${{ env.test_prepared && always() }}
run: |
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
docker exec ${ENV_SERVICE} ./dev/phpstan.sh phar
4 changes: 4 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
- "README.md"
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
tests:
runs-on: ubuntu-20.04
Expand Down
7 changes: 2 additions & 5 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

return (new PhpCsFixer\Config())
->setRules([
'@PHP74Migration' => true,
'@PHP74Migration:risky' => true,
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@DoctrineAnnotation' => true,
Expand Down Expand Up @@ -116,7 +116,6 @@
'return_assignment' => true,
'explicit_string_variable' => true,
'heredoc_to_nowdoc' => true,
'void_return' => false, // BUG:https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/6690
// Symfony 冲突
'braces_position' => [
'control_structures_opening_brace' => 'next_line_unless_newline_at_signature_end',
Expand All @@ -128,8 +127,6 @@
'remove_inheritdoc' => false,
],
'no_null_property_initialization' => false,
// 当支持 php>=8.0 后改配置可以移除
'get_class_to_class_keyword' => false,
])
->setRiskyAllowed(true)
->setFinder(
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"require-dev": {
"composer/semver": "^3.3.2",
"php-cs-fixer/shim": "~3.35.1",
"phpstan/phpstan": "~1.8.0",
"phpstan/phpstan": "~1.10.39",
"phpunit/phpunit": "~9.6",
"rector/rector": "~0.13",
"rector/rector": "~0.18.5",
"symfony/polyfill-uuid": "^1.27",
"yurunsoft/ide-helper": "~1.0",
"yurunsoft/yurun-http": "^5.0.0"
Expand Down
4 changes: 2 additions & 2 deletions dev/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function IDEHelper(): void
'--app-namespace=Imi\\\\Dev',
];
$process = self::createProcess($cmd);
$process->run(static function ($type, $buffer) {
$process->run(static function ($type, $buffer): void {
echo $buffer;
});

Expand Down Expand Up @@ -105,7 +105,7 @@ protected static function parallel(array $processes, int $max, string $titleTemp
{
++$running;
$output->writeln("[{$title}]");
$process->start(static function ($type, $buffer) {
$process->start(static function ($type, $buffer): void {
echo $buffer;
});
}
Expand Down
12 changes: 8 additions & 4 deletions dev/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ function getRectorConfigCallback(string $path): callable
\Rector\Php71\Rector\FuncCall\CountOnNullRector::class,
\Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector::class,
\Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector::class,
\Rector\Php70\Rector\FuncCall\RandomFunctionRector::class,

// 存在兼容问题
\Rector\Php80\Rector\FunctionLike\MixedTypeRector::class, // todo 给接口参数加了`mixed`但没给实现加类型,导致静态分析报错
\Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector::class, // todo 调整包含默认参的参数顺序,会导致代码被破坏
\Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector::class, // 无法正确处理继承覆盖的情况
]);

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

$rectorConfig->sets([LevelSetList::UP_TO_PHP_74]);
$rectorConfig->sets([LevelSetList::UP_TO_PHP_81]);
};
}

Expand Down Expand Up @@ -167,7 +171,7 @@ function checkPorts(array $ports, string $host = '127.0.0.1', int $tryCount = 30
if (isCodeCoverage())
{
putenv('IMI_CODE_COVERAGE_NAME=' . getCodeCoverageName());
(static function () {
(static function (): void {
$filter = new Filter();
$filter->includeDirectory(\dirname(__DIR__) . '/src');
$componentsDir = \dirname(__DIR__) . '/src/Components';
Expand All @@ -185,7 +189,7 @@ function checkPorts(array $ports, string $host = '127.0.0.1', int $tryCount = 30
$codeCoverage->start('imi');

$stoped = false;
$shutdownCallback = static function () use ($codeCoverage, &$stoped) {
$shutdownCallback = static function () use ($codeCoverage, &$stoped): void {
if (!$stoped)
{
$stoped = true;
Expand Down
90 changes: 90 additions & 0 deletions dev/phpstan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash

__DIR__=$(cd `dirname $0`; pwd)
cd "$__DIR__/.."
__DIR__=$(pwd)

components=(
# "core" 默认不处理
"access-control"
"amqp"
"apidoc"
"fpm"
"grpc"
"jwt"
"kafka"
"mqtt"
"pgsql"
"queue"
"rate-limit"
"roadrunner"
"rpc"
"shared-memory"
"smarty"
"snowflake"
"swoole"
"swoole-tracker"
"workerman"
"workerman-gateway"
"macro"
)

analyze_component() {
component="$1"
gen_baseline="$2"
echo "Analyzing: $component, Generate Baseline: $gen_baseline"

analyse_configuration=""

args=()
args+=("--memory-limit" "1G")

if [ "$component" != "core" ]; then
args+=("--configuration=phpstan-components.neon" "--autoload-file=src/Components/$component/vendor/autoload.php" "src/Components/$component")
fi

if [ "$gen_baseline" == "true" ]; then
args+=("--generate-baseline=./phpstan-baseline/baseline-$component.neon" "--allow-empty-baseline")
fi

echo ./vendor/bin/phpstan analyse "${args[@]}"

PHPSTAN_ANALYSE_COMPONENT_NAME="$component" PHPSTAN_GENERATE_BASELINE="$gen_baseline" ./vendor/bin/phpstan analyse "${args[@]}"
}

use_baseline="false"
input_components=()

while [[ $# -gt 0 ]]; do
case "$1" in
--baseline)
use_baseline="true"
shift
;;
-b)
use_baseline="true"
shift
;;
*)
# 如果不是 --baseline 标志,将参数添加到 components 数组中
input_components+=("$1")
shift
;;
esac
done

if [ ${#input_components[@]} -eq 0 ]; then
# If no arguments are provided, analyze all components
for component in "${components[@]}"; do
analyze_component "$component" "$use_baseline"
done
else
# Analyze the specified components provided as arguments
for component in "${input_components[@]}"; do
if [[ " ${components[@]} " =~ " $component " || "core" == "$component" ]]; then
analyze_component "$component" "$use_baseline"
else
echo "Invalid component name: $component"
fi
done
fi
Loading

0 comments on commit fe905f1

Please sign in to comment.