Repository navigation
Ignore PHPStan false positives for WP_REST_Request offset writes - #86284
Conversation
PHPStan rejects every array-access write on WP_REST_Request, valid ones included, because it does not resolve the method-level template that the WordPress stubs declare on offsetSet(). These are not errors to be fixed in Gutenberg, so they move from the baseline to an intentional ignoreErrors entry in phpstan.neon.dist, with a link to the upstream fix so the entry can be removed once a PHPStan release includes it. The baseline is regenerated with `composer phpstan:baselines`, dropping the six entries now covered. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Code-Session-Id: ce560f88-7bfc-4577-bd90-4d370efe8a19
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the ⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. As a site builder, I want to insert a core navigation overlay pattern with CTA and see it on the frontend in
|
|
cc @noruzzamans |
The action callback return.void ignore that trunk added to tools/phpstan/base.neon is an intentional ignore like the WP_REST_Request ones, so it moves into the ignoreErrors section of phpstan.neon.dist under a Level 0 heading. The conflicting baseline is regenerated. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Code-Session-Id: ce560f88-7bfc-4577-bd90-4d370efe8a19
There was a problem hiding this comment.
Thanks for putting this together 👍
It tests well for me.
✅ composer phpstan is clean on the PR merged with current trunk
✅ composer phpstan:baselines leaves no diff
✅ Ignored writes are valid set_param() equivalents
✅ Patterns are anchored to WP_REST_Request
I have one suggestion, not a blocker. Could the two REST entries drop reportUnmatched: false?
Without it, the PHPStan bump with the upstream fix would fail and prompt their removal. That matches how the return.void and baseline entries behave. As is, they would stay quietly.
A small follow-up could mention this list in the PHPStan coding guidelines. They only describe the baseline.
I'm happy to approve and merge this now though. It will unblock a better approach to avoiding PHPStan errors while functions land in Gutenberg before Core.
Yeah, that's true. Removing that would ensure PHPStan complains when the underlying issue is fixed, prompting their removal. So these can be removed the next time we're updating this, but otherwise I'm sure I'll do that once phpstan/phpstan-src#6903 is merged. In any case, the ignoring if the rules would just be some dead code and otherwise harmless. |
What?
See #86088
Moves the PHPStan errors for array-access writes on
WP_REST_Requestout of the baseline and into an intentionalignoreErrorsentry inphpstan.neon.dist, as suggested in #86100 (comment).Why?
Writes like
$request['context'] = 'edit'are reported asoffsetAssign.dimTypeandoffsetAssign.valueTypeerrors, but they are false positives. In the WordPress stubs,WP_REST_Request::offsetSet()uses a method-level template (@template TOffset of key-of<T>,@param T[TOffset] $value), which PHPStan does not resolve for an offset write, so every write is rejected, valid ones included. The equivalentset_param()call is accepted. The fix belongs in PHPStan: phpstan/phpstan-src#6903Rewriting working code to suit a tooling bug (as was tried in #86110 and #86100) is not the right fix. And the baseline records errors that are still to be fixed in Gutenberg, which these are not. Core's
phpstan.neon.distalready keeps such intentional ignores separate from its baseline, so this follows that prior art.How?
ignoreErrorssection tophpstan.neon.distwith two entries, matched on the message and identifier, covering both the bareWP_REST_Requestand genericWP_REST_Request<…>forms. A comment explains the cause and links to the PHPStan PR, so the entries can be removed once a PHPStan release with the fix is required.reportUnmatched: falselets them lapse quietly in the meantime.return.voidignore for action callbacks, added totools/phpstan/base.neonin PHPStan: Ignore return.void errors for action callbacks #86108, into the sameignoreErrorssection, so all intentional ignores live in one place. Entries are grouped under rule-level headings as in core; this one is under Level 0, since theHookCallbackRulethat reports it is not gated by level.tools/phpstan/baseline.neonwithcomposer phpstan:baselines, which drops the sixWP_REST_Requestentries now covered (seven errors, inlib/compat/wordpress-7.1/class-gutenberg-rest-attachments-controller-7-1.phpandlib/media/class-gutenberg-rest-attachments-controller.php). The baseline goes from 58 to 51 errors.Testing Instructions
composer phpstanand confirm it reports no errors.composer phpstan:baselinesand confirmtools/phpstan/baseline.neonhas no further changes.Testing Instructions for Keyboard
Not applicable. There are no UI changes.
Screenshots or screencast
Not applicable.
Use of AI Tools
This PR was authored with Claude Code using Claude Opus 5.5 (medium effort), which wrote the
ignoreErrorsentries, regenerated the baseline, and drafted this description.