Repository navigation
PHPStan: Fix next_tag() string query false positives and quiet the stubs generator - #86109
Conversation
When the stubs are up to date with the recorded source, `composer phpstan:generate-wordpress-stubs` exited without any output, which looked like it did nothing. It now says which source the stubs were generated from, and that `--force` generates them again. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Code-Session-Id: 2c14c65e-32a4-4332-8e55-c2d31a16a529
`composer phpstan` runs the generator before every analysis, so the notice that the stubs are already generated was printed on every run, where it is only noise. It is meant for running `composer phpstan:generate-wordpress-stubs` directly. With `--quiet`, which `composer phpstan` now passes, the notice is left out. Generating the stubs is still reported, since that takes a while and changes what gets analyzed. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Code-Session-Id: 2c14c65e-32a4-4332-8e55-c2d31a16a529
🤖 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. The navigation text color should apply to all navigation links including submenu and overlay text in
|
…pdate/phpstan-stubs-up-to-date-notice
The typing of HTML API tag queries and tag names is now committed to core in r65220, so the stubs are generated from that trunk commit instead of from the pull request. The baseline no longer has the `wp_tag_cloud()` argument error, which the newer stubs resolve. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Code-Session-Id: 2c14c65e-32a4-4332-8e55-c2d31a16a529
There was a problem hiding this comment.
This looks good to me. I left one optional nit for the alignment of the --commit line in the usage text, which shouldn't block merging.
I tested it in Docker (PHP 8.5.12, Composer 2.11.1, PHPStan 2.3.4), using dependencies installed without a lock file and PHP files from an existing local build:
- With no stubs,
composer phpstan:generate-wordpress-stubsgenerates them fromWordPress/wordpress-develop@140b18225239(r65220). - Running it again reports that they are already generated, and exits with status 0.
- With
--quiet, the generator prints nothing and exits with status 0. - The notice goes to standard error, so standard output stays empty.
-- --forcegenerates the stubs again.composer phpstandoes not print the notice, and reports no errors. SincereportUnmatchedIgnoredErrorsis on, that also confirms that the baseline has no stale entries.
I also confirmed that the baseline drops 25 entries: 24 for next_tag(), covering 27 errors, and 1 for wp_tag_cloud().
AI Review: Claude Opus 5.5
Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@git.wordpress.org>
What?
See #86088, in particular #86088 (comment).
This removes the 27 false-positive
argument.typeerrors (24 baseline entries) for passing a tag name toWP_HTML_Tag_Processor::next_tag(), such asnext_tag( 'FIGURE' ), by generating the WordPress stubs from the core change that types$query. It also makes the stubs generator say when it has nothing to do, and keepscomposer phpstanquiet about that.Why?
Core documents the
$queryparameter ofnext_tag()asarray|string|null, but the hash notation only describes the array form. When the stub generator turns that hash into a@phpstan-paramarray shape, it drops thestringform, so every call that passes a bare tag name is reported. Core has no such errors, since its own analysis reads the@paramtype directly.Separately,
composer phpstan:generate-wordpress-stubsprinted nothing at all when the stubs were already up to date, which looked like it had silently failed.How?
WP_HTML_Tag_ProcessorandWP_HTML_Processor, so the generator no longer has to derive a shape from the hash. It was committed in r65220, the stubs are regenerated from that commit on trunk, and the baseline drops the 24next_tag()entries. The newer stubs also include r65161, which fixes thewp_tag_cloud()argument error in the Tag Cloud block, so that baseline entry is dropped too.--forcegenerates them again.--quietoption leaves that notice out.composer phpstan, which runs the generator before every analysis, passes it, so the notice only appears when the generator is run directly. Generating the stubs is still reported either way.Testing Instructions
composer phpstan:generate-wordpress-stubs. If the stubs need generating, they are generated. Run it again, and it reports that the stubs are already generated fromWordPress/wordpress-develop@140b18225239, and exits with status 0.composer phpstan:generate-wordpress-stubs -- --force, and the stubs are generated again.composer phpstan. It does not print the notice, and PHPStan reports no errors.tools/phpstan/baseline.neonno longer has entries fornext_tag()being passed a string.Testing Instructions for Keyboard
Not applicable, since this only changes development tooling.
Screenshots or screencast
Not applicable.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5 (medium effort)
Used for: Implementing the generator notice and
--quietoption, and writing this description. The changes were directed and reviewed by me, and the stubs and baseline were regenerated by me.