Skip to content

chore(static-analysis): type coverage results as CoverageResult for PHPStan 2.2#264

Merged
wadakatu merged 1 commit into
mainfrom
fix/phpstan-2.2-sealed-shape-types
Jun 3, 2026
Merged

chore(static-analysis): type coverage results as CoverageResult for PHPStan 2.2#264
wadakatu merged 1 commit into
mainfrom
fix/phpstan-2.2-sealed-shape-types

Conversation

@wadakatu
Copy link
Copy Markdown
Collaborator

@wadakatu wadakatu commented Jun 3, 2026

概要

PHPStan 2.2 で sealed array shape のチェックが厳格化され、array<string, mixed> を sealed な CoverageResult / EndpointSummary 期待箇所へ渡すコードが新たにエラー化しました。composer.lock が gitignore されているため CI は毎回 PHPStan を最新解決しており、この厳格版を取り込んで 19 件のエラーで CI(PHPStan ジョブ / PHP 8.3)が落ちています。main でも同一エラーを再現します(既存問題で、特定機能 PR とは無関係)。

変更内容

カバレッジ系の renderer/evaluator 呼び出し箇所の緩い array<string, mixed> 注釈を、OpenApiCoverageTracker で定義済みの CoverageResult / EndpointSummary エイリアスへ置き換え(ヘルパは既に完全な shape を構築済み)。型注釈のみでランタイム挙動の変更なし。

  • src/Coverage/CoverageMergeCommand.php: computeResults()@returnarray<string, CoverageResult> に是正(computeCoverageOn() の実戻り値どおり)。evaluateThresholdGate()@param も同様に是正し、不要なインライン @var を撤去。
  • tests/Unit/Coverage/CoverageThresholdEvaluatorTest.php: counts()@returnCoverageResult に(@phpstan-import-type 追加)。
  • tests/Unit/Coverage/{Html,JUnit}CoverageRendererTest.php: renderOne()$endpointEndpointSummary に。
  • tests/Unit/Coverage/JsonCoverageRendererTest.php: oneSpecResults()@returnarray<string, CoverageResult> に。
  • tests/Unit/Coverage/MarkdownCoverageRendererLintTest.php: endpoint()EndpointSummary*Fixture() / lint ヘルパを array<string, CoverageResult> に。

検証

PHP 8.3(CI と同条件、composer install で最新依存を解決 → PHPStan 2.2.1)で:

  • vendor/bin/phpstan analyseNo errors(19 → 0)
  • vendor/bin/phpunit → 1856 tests グリーン
  • php-cs-fixer --dry-run → クリーン

関連情報

…HPStan 2.2

PHPStan 2.2 tightened sealed-array-shape checking and now rejects passing
`array<string, mixed>` where a sealed `CoverageResult` / `EndpointSummary`
shape is expected. Because composer.lock is gitignored, CI resolves PHPStan
fresh and picked up the stricter release, surfacing 19 pre-existing errors
across the coverage renderers/evaluator call sites (also reproducible on
main).

Replace the loose `array<string, mixed>` annotations with the precise
imported `CoverageResult` / `EndpointSummary` aliases (the helpers already
build complete shapes): `CoverageMergeCommand::computeResults()` /
`evaluateThresholdGate()` and the coverage renderer test fixtures. No runtime
behaviour change — annotations only.
@wadakatu wadakatu merged commit 6585925 into main Jun 3, 2026
16 checks passed
@wadakatu wadakatu deleted the fix/phpstan-2.2-sealed-shape-types branch June 3, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant