Skip to content

Compatibility fixes for PHPStan 2.1.52#351

Merged
janedbal merged 1 commit intomasterfrom
jn-fix-phpstan-2.1.52
Apr 28, 2026
Merged

Compatibility fixes for PHPStan 2.1.52#351
janedbal merged 1 commit intomasterfrom
jn-fix-phpstan-2.1.52

Conversation

@janedbal
Copy link
Copy Markdown
Member

Summary

Two errors surface on PHPStan 2.1.52 (CI uses composer update, so any new PR pulls the latest):

  • tests/Cache/UsageCacheStorageTest.php:82staticMethod.alreadyNarrowedType on assertCount(2, $restored). The narrowing is a regression in 2.1.52: nested foreach over a non-empty-list<T> collapses to an exact-count tuple instead of non-empty-list<T>. Bisected to 2.1.51 → 2.1.52. Reported upstream: Since 2.1.52 nested foreach over non-empty-list<T> narrows accumulated array to exact count phpstan/phpstan#14543. Suppressed locally with @phpstan-ignore referencing the issue.
  • tests/Rule/DeadCodeRuleTest.php:1373offsetAccess.nonArray for destructuring $error->getMetadata(). The previous floating /** @var BlackMember */ / /** @var bool */ tags don't help with destructuring; replaced with a @var on $metadata declaring the shape the rule actually emits.

Lockfile bumped to 2.1.52 to match what CI runs.

Two new errors surface on PHPStan 2.1.52 (CI uses `composer update`,
so any new PR pulls the latest):

- tests/Cache/UsageCacheStorageTest.php:82 — `staticMethod.alreadyNarrowedType`
  on `assertCount(2, $restored)`. The narrowing comes from a regression
  in 2.1.52 where a nested foreach over `non-empty-list<T>` is collapsed
  to an exact-count tuple. Reported upstream:
  phpstan/phpstan#14543
- tests/Rule/DeadCodeRuleTest.php:1373 — `offsetAccess.nonArray` for
  destructuring `$error->getMetadata()`. Annotate `$metadata` with the
  shape the rule actually emits so destructuring is well-typed.

Lockfile bumped to 2.1.52 to match what CI runs.
@janedbal janedbal merged commit 71d251c into master Apr 28, 2026
32 checks passed
@janedbal janedbal deleted the jn-fix-phpstan-2.1.52 branch April 28, 2026 16:21
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