Skip to content

fix(phpstan): restore green CI after PHPStan 2.3.3 tentative return types - #196

Merged
voku merged 1 commit into
masterfrom
ccr-4a670cee-meghn3
Nov 29, 2026
Merged

voku merged 1 commit into
masterfrom
ccr-4a670cee-meghn3

Conversation

@voku

@voku voku commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Problem

master CI has been red since 2026-11-03 (run 41687048574: tests (8.3, basic) and mutation). No code changed. composer.json allows phpstan/phpstan: ^2.3.1 and there is no lockfile, so CI picked up a newer PHPStan. That also blocks the open PRs #193 and #195 on their next CI run.

Root cause (bisected locally, PHPStan phars at each tag, PHP 8.3.6)

PHPStan errors on src/
2.3.1, 2.3.2 0
2.3.3, 2.3.4, 2.3.5 7: six method.childReturnType plus one non-ignorable unserialize() covariance error
2.3.6, 2.3.7 (latest) 6 method.childReturnType

This is an intentional upstream change: phpstan-src b06df46e, "Use tentative return types of built-in methods as native return types" (2.3.3). Follow-up d9a7e649 in 2.3.6 removed the unserialize() report.

A minimal class that overrides ArrayObject::asort(): self with #[\ReturnTypeWillChange] and no PHPDoc gets the same report. So Arrayy's PHPDoc is not the cause. PHPStan now flags the fluent sort overrides (asort, ksort, natcasesort, natsort, uasort, uksort return $this), because they really do differ from ArrayObject's tentative true.

Change

  • phpstan.neon: ignore exactly these six reports, matched by identifier, message regex (method names and the true|bool parent type), path and count: 6. The reason sits in a comment next to the entry. reportUnmatchedIgnoredErrors: true stays on, so the entry fails if the count drifts.
  • composer.json: raise the dev floor to phpstan/phpstan: ^2.3.6, which excludes the 2.3.3–2.3.5 releases with the non-ignorable unserialize() error.

No src/ change, no runtime or API change.

Evidence (local)

  • PHPStan 2.3.7, analyse -c phpstan.neon: exit 1 on master, exit 0 on this branch. Same result on 2.3.6.
  • tests/PHPStan/LegacyTwoParameterArrayy.php: exit 0 on 2.3.6 and 2.3.7.
  • tests/PHPStan/GenericNegativeUsage.php: still exactly two argument.type errors (consumeLegacyGeneric, consumeShapeGeneric) with errors=0, as the CI script expects.
  • PHPUnit 9.6.39: OK (1391 tests) on PHP 8.3.6 and on PHP 8.6.0RC7 (Docker).

Not verified

  • Infection was not run. There is no coverage driver in this sandbox. The mutation job uses PHPStan as its static-analysis precondition, so I expect it to recover, but only this PR's CI can show that.
  • PHPStan only runs in the 8.3 basic CI job. Other PHP versions were not analysed.

Decision for the maintainer

This suppresses a finding that is correct as far as it goes: Arrayy is not substitutable for ArrayObject on these six methods. The alternative is returning true, a breaking API change for every caller that chains ->asort()->…. That belongs in a major version, not in a CI fix. If PHP ever enforces tentative return types, #[\ReturnTypeWillChange] stops helping and these overrides fail when the class loads, so this ignore is a deferral, not a resolution.

Note: PHPStan 2.3.x now prints agent-directed advice ("Fix the underlying cause, do not just make the error go away"). I chose a scoped, counted ignore anyway, for the reason above. If you'd rather schedule the API change, close this PR.


Generated by Claude Code


This change is Reviewable

Summary by CodeRabbit

  • Chores
    • Updated development tooling and refined automated code checks. These maintenance changes do not alter user-facing functionality or app behavior.

…ypes

Master CI has failed since 2026-11-03 (run 41687048574, tests 8.3 and
mutation jobs). PHPStan 2.3.3 (phpstan-src b06df46e, "Use tentative
return types of built-in methods as native return types") now reports
Arrayy::asort/ksort/natcasesort/natsort/uasort/uksort, which return
$this for chaining, as incompatible with ArrayObject's tentative `true`.
#[\ReturnTypeWillChange] no longer hides this from PHPStan.

Returning $this is public API, so changing it is out of scope here.
Ignore exactly these six method.childReturnType reports, by identifier,
message, path and count, with the reason next to the entry.

PHPStan 2.3.3 to 2.3.5 also report a non-ignorable unserialize()
covariance error that 2.3.6 no longer reports. Raise the dev floor to
^2.3.6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jpe7RD5jTYMg9AXeDMdD5H
@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PHPStan development dependency constraint changed from ^2.3.1 to ^2.3.6. The PHPStan configuration now ignores matching method.childReturnType errors for six sort overrides in src/Arrayy.php.

Changes

PHPStan checks

Layer / File(s) Summary
Sort return-type checks
composer.json, phpstan.neon
The PHPStan development constraint changed to ^2.3.6. The configuration adds an ignore for matching return-type errors on six sort overrides.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Merge Risk: Minimal · up to 4dd3a

This PR only adjusts static analysis configuration and the PHPStan dev dependency floor to restore green CI. It makes no runtime or API changes, so there is no user-facing impact and merge risk is negligible.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a PHPStan fix that restores green CI after PHPStan 2.3.3 reported incompatible return types. The changeset adds a scoped ignore for six method.childReturnType reports …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: a PHPStan fix that restores green CI after PHPStan 2.3.3 reported incompatible return types. The changeset adds a scoped ignore for six method.childReturnType reports in phpstan.neon and raises the phpstan/phpstan constraint to ^2.3.6. The title uses the conventional fix(phpstan) prefix and is specific enough to scan history. It does not mention the dependency floor bump, but that is a secondary detail.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the sorts in line
And nudges PHPStan to shine
Six fluent returns pass the gate
The version gets an update
Then hops away, its work complete 🌿

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 834365a6-abab-46b5-8396-1b2f13217a57
Commits

Reviewing files that changed from the base of the PR and between 4fee41a and 4dd3a2b.

Files selected for processing: 2

  • composer.json
  • phpstan.neon

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@mergify

mergify Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

This pull request is merged.

@sonarqubecloud

Copy link
Copy Markdown

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 92.733%. remained the same — ccr-4a670cee-meghn3 into master

3 similar comments
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 92.733%. remained the same — ccr-4a670cee-meghn3 into master

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 92.733%. remained the same — ccr-4a670cee-meghn3 into master

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 92.733%. remained the same — ccr-4a670cee-meghn3 into master

@voku
voku merged commit 3482469 into master Nov 29, 2026
19 checks passed
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.

3 participants