chore(static-analysis): type coverage results as CoverageResult for PHPStan 2.2#264
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
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()の@returnをarray<string, CoverageResult>に是正(computeCoverageOn()の実戻り値どおり)。evaluateThresholdGate()の@paramも同様に是正し、不要なインライン@varを撤去。tests/Unit/Coverage/CoverageThresholdEvaluatorTest.php:counts()の@returnをCoverageResultに(@phpstan-import-type追加)。tests/Unit/Coverage/{Html,JUnit}CoverageRendererTest.php:renderOne()の$endpointをEndpointSummaryに。tests/Unit/Coverage/JsonCoverageRendererTest.php:oneSpecResults()の@returnをarray<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 analyse→ No errors(19 → 0)vendor/bin/phpunit→ 1856 tests グリーンphp-cs-fixer --dry-run→ クリーン関連情報
composer.lockの gitignore により CI が PHPStan を最新解決する設計(= 最新ツールでの継続検証)のため、ツール側の厳格化がそのまま顕在化したもの。