Repository navigation
PHPStan: Update to 2.3.5 and recommend --fix for the baseline - #86333
westonruter wants to merge 6 commits into
Conversation
The analysis reports no errors with this release, and no baseline entry goes stale, so the baseline is unchanged. The other PHPStan packages, phpstan-phpunit (2.1.1), extension-installer (1.4.3), and szepeviktor/phpstan-wordpress (2.0.4), are already at their latest versions. The `WP_REST_Request` offset ignores stay, since the PHPStan fix they wait on (phpstan/phpstan-src#6903) is not yet merged. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3GdCg3QL5KeMvuQvwf Claude-Code-Session-Id: 5bac4eea-faaa-40e6-8440-b696b7773ba6
PHPStan 2.3.5 can fix stale ignores itself: `--fix` lowers a baseline count that is now too high, removes an entry that matches nothing, and removes an `@phpstan-ignore` comment that no longer ignores anything. Verified on `tools/phpstan/baseline.neon`: an inflated count was lowered back to its real value, leaving the rest of the file as it was. That suits Gutenberg better than regenerating. `composer phpstan:baselines` is PHPStan's `--generate-baseline`, which records every error the run reports, so the job summary had to warn against regenerating while other errors were still reported. `--fix` never adds an entry, so it is safe to run then too. The coding guidelines and the job summary now recommend `--fix`, and explain that it has to be a run over all the paths, since PHPStan reports no out-of-date entries when it analyzes only some files. `report.ts` also reads the `fixable` flag that PHPStan's JSON report now carries: an annotation of a fixable error says how to fix it, and the job summary marks the error with 🔧, as PHPStan's table output does. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3GdCg3QL5KeMvuQvwf Claude-Code-Session-Id: 5bac4eea-faaa-40e6-8440-b696b7773ba6
🤖 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 📦 Bundle sizeSize Change: 0 B Total Size: 8.63 MB
⚡ 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. Page List converts to Navigation Links with entity bindings in
|
Resolves the conflict in the coding guidelines, where trunk split the PHPStan paragraph into subsections. Trunk's structure is kept, and the recommendation of `--fix` for out-of-date baseline entries is applied to its "The baseline" subsection. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3GdCg3QL5KeMvuQvwf Claude-Code-Session-Id: 5bac4eea-faaa-40e6-8440-b696b7773ba6
Removing an out-of-date baseline entry meant running `composer phpstan -- --fix`. Leaving out the `--` makes Composer discard the flag silently, so the analysis just reports the stale entries again. `composer phpstan:fix` (and `npm run typecheck:php:fix`) chains two steps, the second run only when the first succeeds: * PHPStan with `--fix`, which lowers or removes the stale entries. * The analysis once more, since PHPStan's `--fix` reports only what it fixed, and succeeds even when other errors remain. It reuses the result cache, so it is quick. Both analyses use `phpstan.neon.dist`, whatever a local `phpstan.neon` says. A configuration at another rule level can report a baselined error with a different message, and `--fix` then removes entries the default configuration still needs. When nothing is fixable, PHPStan exits with 1 and stops the chain, which the coding guidelines note. The coding guidelines, the README, and the CI annotation and job summary now point to the new scripts. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3GdCg3QL5KeMvuQvwf Claude-Code-Session-Id: 5bac4eea-faaa-40e6-8440-b696b7773ba6
The comment above the baseline include in `phpstan.neon.dist` still recommended `composer phpstan -- --fix`. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tnky3GdCg3QL5KeMvuQvwf Claude-Code-Session-Id: 5bac4eea-faaa-40e6-8440-b696b7773ba6
|
The companion core PR has been merged: WordPress/wordpress-develop#15479. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified across the PHPStan tooling updates, CI guidance, configuration, and contributor documentation.
No open issues 🎉
What changed in this PR
Updates Gutenberg’s PHPStan tooling to version 2.3.5 and introduces a dedicated workflow for removing stale baseline entries without regenerating the entire baseline.
Changes:
- Adds
composer phpstan:fixandnpm run typecheck:php:fixwith a follow-up analysis for remaining errors. - Updates CI reporting to identify fixable PHPStan errors and recommend the new workflow.
- Revises PHPStan configuration and contributor documentation.
| File | Description |
|---|---|
| tools/phpstan/report.ts | Reports PHPStan errors marked as fixable and includes guidance for running the baseline-fix command. |
| tools/phpstan/README.md | Documents stale baseline cleanup using the new PHPStan fix workflow. |
| phpstan.neon.dist | Updates PHPStan baseline maintenance guidance. |
| package.json | Adds the local-environment wrapper for the PHPStan baseline-fix command. |
| docs/contributors/code/coding-guidelines.md | Replaces baseline regeneration guidance with instructions for the safer fix workflow. |
| composer.json | Updates PHPStan to 2.3.5 and adds the two-step baseline-fix Composer script. |
Review effort: Lite
ramonjd
left a comment
There was a problem hiding this comment.
I'm not a great authority on this sort of stuff so take my review with all the salt you need.
Thanks for the upgrade. I ran the commands and they behaved as expected.
Using --fix to clean the baseline makes sense from what I can understand.
I got Claude to look into PHPStan 2.3.5's source to check the exit codes the PR relies on, and they match.
One thing I noticed in the terminal - composer phpstan:fix fails when there’s nothing to fix. would that be confusing for some folks? i don't know about best practice here. could the script should treat "nothing to fix" as something that's desirable, like success?
What?
Follow up to #66693. Companion to WordPress/wordpress-develop#15479, which does the same for core.
Updates PHPStan from 2.3.4 to 2.3.5, and adds
composer phpstan:fix(andnpm run typecheck:php:fix), which uses its new--fixoption to remove out-of-date baseline entries rather than regenerating the baseline.Why?
PHPStan 2.3.5 marks the errors it can fix itself with 🔧, and these include stale ignores.
--fixlowers a baseline count that is now too high, removes an entry that matches nothing, and removes an@phpstan-ignorecomment that no longer ignores anything.That suits Gutenberg better than regenerating.
composer phpstan:baselinesis PHPStan's--generate-baseline, which records every error the run reports, so the job summary had to warn against regenerating while other errors were still reported.--fixnever adds an entry, so it is safe to run then too.Running it as
composer phpstan -- --fixis easy to get wrong, though: leaving out the--makes Composer discard the flag silently, so the analysis just reports the stale entries again. And with--fix, PHPStan reports only what it fixed, and exits with 0 when every fixable error was fixed, even when other errors remain. A dedicated script avoids both.How?
Bumps
phpstan/phpstanto 2.3.5. The analysis reports no errors with it and no baseline entry goes stale, so the baseline is unchanged. phpstan-phpunit, extension-installer, and phpstan-wordpress are already at their latest versions. TheWP_REST_Requestoffset ignores stay, since Resolve offsetSet() template types for ArrayAccess offset writes phpstan/phpstan-src#6903 is not merged yet.Adds
composer phpstan:fix, which chains two steps, the second run only when the first succeeds:phpstan analyse --configuration=phpstan.neon.dist --fix, which updates the baseline in place.phpstan analyse --configuration=phpstan.neon.dist, since--fixreports only what it fixed. It reuses the result cache, so it is quick, and it is what makes the script fail when errors remain.Both analyses name
phpstan.neon.dist, whatever a localphpstan.neonsays. In core, running--fixwith a local configuration at level 10 with bleeding edge removed entries the default configuration still needs, because that configuration reports those errors with different messages. When nothing is fixable, PHPStan exits with 1 and stops the chain after the first step, which the coding guidelines note.npm run typecheck:php:fixruns the script in the local environment.The coding guidelines,
tools/phpstan/README.md,phpstan.neon.dist, and the annotation and job summary written byreport.tsnow point tocomposer phpstan:fix(ornpm run typecheck:php:fix). The guidelines note that--fixhas to be a run over all the paths, since PHPStan reports no out-of-date entries when it analyzes only some files.report.tsreads thefixableflag PHPStan's JSON report now carries. A fixable error's annotation says how to fix it, and the job summary marks it with 🔧, as PHPStan's table output does.Not adopted: registering
tools/phpstan/src/services with PHPStan's new attributes, since that only works when PHPStan runs on PHP 8.0+ and Gutenberg supports 7.4.Unlike core, which keeps one baseline per identifier and gains a
--pruneoption there for deleting a baseline that--fixempties, Gutenberg has a single baseline, so no pruning step is needed.Testing Instructions
composer update, thennpm run buildandcomposer phpstan. No errors are reported.composer phpstan:fix. It fails with "No fixable errors found", and changes nothing.tools/phpstan/baseline.neon, raise thecountof any entry.composer phpstan. The entry is reported asignore.count, marked with 🔧.composer phpstan:fix. The count is lowered back, nothing else in the file changes, and the second analysis reports no errors.report.ts, write a report withcomposer phpstan -- --error-format=json > report.jsonwhile the count is raised, then runGITHUB_STEP_SUMMARY=summary.md npm run --workspace @wordpress/phpstan-tools report -- report.json. The annotation andsummary.mdmentioncomposer phpstan:fix.Use of AI Tools
Written with Claude Code using Claude Opus 5.5 (medium effort): researching the 2.3.5 changes, testing
--fixagainst the baseline, and writing the version bump, thephpstan:fixscript, documentation, andreport.tschanges, all reviewed by me.