Skip to content

fix(test): remove stale phpstan ignores in CollectionNormalizerTest#8384

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/phpstan-85-stale-ignores
Jul 3, 2026
Merged

fix(test): remove stale phpstan ignores in CollectionNormalizerTest#8384
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/phpstan-85-stale-ignores

Conversation

@soyuka

@soyuka soyuka commented Jul 3, 2026

Copy link
Copy Markdown
Member

The failure

The PHPStan CI job (PHP 8.5) on 4.3 fails:

src/Hal/Tests/Serializer/CollectionNormalizerTest.php
  128  No error to ignore is reported on line 128.  ignore.unmatchedLine (non-ignorable)
  129  No error to ignore is reported on line 129.  ignore.unmatchedLine (non-ignorable)
[ERROR] Found 2 errors

Root cause

composer.lock pins phpstan/phpstan to 2.2.3. That version improved conditional-type narrowing: inside the if (!$partial) branch of normalizePaginator(), PHPStan now correctly infers that $paginator is a PaginatorInterface (which declares getLastPage() / getTotalItems()), because it correlates the $partial bool used to select the mocked interface with the later if (!$partial) guard.

Earlier PHPStan (2.1.x) lost that correlation and emitted a phpunit.mockMethod error ("Trying to mock an undefined method getLastPage() on ... PartialPaginatorInterface"), which the // @phpstan-ignore-line comments on lines 128-129 suppressed.

Now that the underlying error is no longer reported, those ignores are unmatched, and reportUnmatchedIgnoredErrors (PHPStan default) turns them into non-ignorable hard failures.

Fix

Remove the two stale // @phpstan-ignore-line comments. The code is untouched. The adjacent valid() / current() ignores just above (lines 124-125) are still matched and left in place.

Verified with PHPStan 2.2.3 (the exact locked version): [OK] No errors. php-cs-fixer clean.

composer.lock pins phpstan/phpstan to 2.2.3, and that version improved
conditional-type narrowing: it now correctly infers that inside the
`if (!$partial)` branch, $paginator is PaginatorInterface (which
declares getLastPage()/getTotalItems()), whereas 2.1.x lost that
correlation and reported a phpunit.mockMethod error there. The
`@phpstan-ignore-line` comments suppressing that error are now
unmatched, and reportUnmatchedIgnoredErrors turns unmatched ignores
into hard failures. Removed the two stale ignores; the adjacent
valid()/current() ignores above are still matched and left in place.
@soyuka soyuka merged commit 340e982 into api-platform:4.3 Jul 3, 2026
111 of 112 checks passed
@soyuka soyuka deleted the fix/phpstan-85-stale-ignores branch July 3, 2026 05: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