From 6469f96b25a3bcfce9397720927015d7a4897d59 Mon Sep 17 00:00:00 2001 From: JanHuang <384099566@qq.com> Date: Tue, 27 Oct 2026 00:05:39 +0800 Subject: [PATCH 1/4] =?UTF-8?q?chore:=20=E6=8E=A5=E5=85=A5=20PHPStan=20?= =?UTF-8?q?=E5=9F=BA=E7=BA=BF=E4=B8=8E=E8=A6=86=E7=9B=96=E7=8E=87=E9=97=A8?= =?UTF-8?q?=E6=A7=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - require-dev phpstan/phpstan ^1.12.24,level 5 基线 - CI 增加 PHPStan 步骤 - CI 使用 Xdebug 生成 clover 覆盖率并校验阈值(阈值待测量后固化) --- .github/workflows/ci.yml | 26 +++++++++++++++++++--- composer.json | 48 ++++++++++++++++++++++------------------ phpstan.neon | 4 ++++ 3 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 phpstan.neon diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02aae24..0682cdf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,11 +18,31 @@ jobs: with: php-version: '8.4' extensions: mbstring - coverage: none + coverage: xdebug tools: composer:v2 - name: Validate composer.json run: composer validate --no-check-publish --no-check-lock - name: Install dependencies run: composer update --prefer-dist --no-progress --no-interaction - - name: Run tests - run: vendor/bin/phpunit --no-coverage + - name: PHPStan + run: vendor/bin/phpstan analyse --no-progress --memory-limit=1G + - name: Run tests with coverage + run: | + mkdir -p build + vendor/bin/phpunit --coverage-clover=build/coverage.xml + - name: Enforce coverage threshold + env: + COVERAGE_MIN: '0' + run: | + php -r ' + $xml = simplexml_load_file("build/coverage.xml"); + $metrics = $xml->project->metrics; + $total = (int) $metrics["statements"]; + $covered = (int) $metrics["coveredstatements"]; + $pct = $total > 0 ? 100 * $covered / $total : 0.0; + printf("Coverage: %.2f%% (minimum %.2f%%)\n", $pct, (float) getenv("COVERAGE_MIN")); + if ($pct < (float) getenv("COVERAGE_MIN")) { + fwrite(STDERR, "Coverage below threshold\n"); + exit(1); + } + ' diff --git a/composer.json b/composer.json index b4361af..f50e49d 100755 --- a/composer.json +++ b/composer.json @@ -1,25 +1,29 @@ { - "name": "fastd/container", - "description": "FastD Container", - "type": "library", - "keywords": ["FastD", "container"], - "license": "MIT", - "authors": [ - { - "name": "janhuang", - "email": "384099566@qq.com" + "name": "fastd/container", + "description": "FastD Container", + "type": "library", + "keywords": [ + "FastD", + "container" + ], + "license": "MIT", + "authors": [ + { + "name": "janhuang", + "email": "384099566@qq.com" + } + ], + "require": { + "php": ">=8.4", + "psr/container": "^2.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.0", + "phpstan/phpstan": "^1.12.24" + }, + "autoload": { + "psr-4": { + "FastD\\Container\\": "src" + } } - ], - "require": { - "php": ">=8.4", - "psr/container": "^2.0" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "autoload": { - "psr-4": { - "FastD\\Container\\": "src" - } - } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..91e6453 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 5 + paths: + - src From aed4641ec51b586fcd7294c72217dfe52cd5f525 Mon Sep 17 00:00:00 2001 From: JanHuang <384099566@qq.com> Date: Tue, 27 Oct 2026 00:09:02 +0800 Subject: [PATCH 2/4] =?UTF-8?q?ci:=20=E9=85=8D=E7=BD=AE=20PHPUnit=20source?= =?UTF-8?q?=20filter=20=E5=B9=B6=E4=BF=AE=E6=AD=A3=20dobee=20phpstan=20?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PHPUnit 10 覆盖率需要 配置 - dobee 的 Composer bin-dir 为 bin,PHPStan 使用 bin/phpstan --- phpunit.xml.dist | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 31ffb94..4aa465f 100755 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,10 @@ - + + + + src + + tests From bbb78bff3d8dd76635192ecf5adc47b37401806e Mon Sep 17 00:00:00 2001 From: JanHuang <384099566@qq.com> Date: Tue, 27 Oct 2026 00:11:53 +0800 Subject: [PATCH 3/4] =?UTF-8?q?ci:=20=E4=BD=BF=E7=94=A8=20PCOV=20=E7=94=9F?= =?UTF-8?q?=E6=88=90=E8=A6=86=E7=9B=96=E7=8E=87=E5=B9=B6=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20PHPStan=20=E7=B1=BB=E5=8F=91=E7=8E=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0682cdf..5ec6222 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: with: php-version: '8.4' extensions: mbstring - coverage: xdebug + coverage: pcov tools: composer:v2 - name: Validate composer.json run: composer validate --no-check-publish --no-check-lock From 0c9bbb80ffb0a87ea62106cc4f289ec4760c776e Mon Sep 17 00:00:00 2001 From: JanHuang <384099566@qq.com> Date: Tue, 27 Oct 2026 00:21:44 +0800 Subject: [PATCH 4/4] =?UTF-8?q?ci:=20=E5=9B=BA=E5=8C=96=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E7=8E=87=E9=97=A8=E6=A7=9B=E4=B8=BA=2075%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ec6222..d5d2d74 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: vendor/bin/phpunit --coverage-clover=build/coverage.xml - name: Enforce coverage threshold env: - COVERAGE_MIN: '0' + COVERAGE_MIN: '75' run: | php -r ' $xml = simplexml_load_file("build/coverage.xml");