Repository navigation
Code Quality: Fix the varTag.noVariable PHPStan errors and remove the baseline - #15449
mukeshpanchal27 wants to merge 2 commits into
Conversation
A `@var` tag documents a variable or a property. Above a `define()` call it has no variable to describe, so PHPStan reports `varTag.noVariable`. PHPStan already infers each constant's type from its value. Most `define()` docblocks in core have no `@var` tag: 174 have none and 17 have one. The `CUSTOM_TAGS` tag was also wrong. It documented `array[]|false`, but the constant is a boolean flag, and core only checks `! CUSTOM_TAGS`. Its description now says to define the constant as `true` to use the custom tag globals. This change removes eight `@var` tags and the matching `varTag.noVariable` baseline entries. There is no runtime change. See #65817. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ignments. `WP_Query` had nine `/** @var Type */` tags above assignments to `$this->posts`, `$this->post`, `$this->comments` and `$this->comment`. PHPStan reports each one as `varTag.noVariable`. A `@var` tag can only name a local variable, so PHPStan ignores these tags and cannot use them. Naming the property, as in `@var WP_Post[] $this->posts`, makes PHPStan read the type as `$this` and report new errors. The property docblocks already document these types. This change removes the nine tags, deletes the now empty `varTag.noVariable` baseline, and removes its `includes` line from `phpstan.neon.dist`. There is no runtime change. See #65817. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: 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:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
🟢 Approval recommended
The review identifies no active issues, with the change limited to removing invalid PHPStan annotations, correcting documentation, and deleting the obsolete baseline.
No open issues 🎉
What changed in this PR
This pull request removes all 17 invalid PHPStan varTag.noVariable violations, updates the CUSTOM_TAGS documentation, and removes the obsolete PHPStan baseline. It does not change runtime behavior.
Changes:
- Removes invalid
@varannotations abovedefine()calls. - Removes unsupported inline
@varannotations fromWP_Queryproperty assignments. - Corrects the
CUSTOM_TAGSdocumentation. - Deletes the dedicated PHPStan baseline and its configuration include.
| File | Description |
|---|---|
tests/phpstan/baselines/varTag.noVariable.neon |
Deletes the obsolete PHPStan error baseline. |
src/xmlrpc.php |
Removes the invalid annotation above XMLRPC_REQUEST. |
src/wp-includes/rest-api.php |
Removes invalid annotations above REST API constants. |
src/wp-includes/kses.php |
Corrects CUSTOM_TAGS documentation and removes its invalid annotation. |
src/wp-includes/class-wp-query.php |
Removes unsupported inline property annotations. |
src/wp-cron.php |
Removes the invalid annotation above DOING_CRON. |
src/wp-admin/upgrade.php |
Removes the invalid annotation above WP_INSTALLING. |
src/wp-admin/profile.php |
Removes the invalid annotation above IS_PROFILE_PAGE. |
src/wp-admin/install.php |
Removes the invalid annotation above WP_INSTALLING. |
phpstan.neon.dist |
Removes the deleted baseline from the PHPStan includes. |
Review effort: Lite
This PR fixes all 17
varTag.noVariableerrors and deletestests/phpstan/baselines/varTag.noVariable.neon. There is no runtime change.PHPStan reports
varTag.noVariablewhen a@vartag has no variable name and is not above a local variable assignment. The errors fall into two groups, and each group has its own commit.@vartags abovedefine()calls (8 errors)Files:
wp-admin/install.php,wp-admin/profile.php,wp-admin/upgrade.php,wp-cron.php,wp-includes/kses.php,wp-includes/rest-api.php(2) andxmlrpc.php.A
@vartag above adefine()call has no variable to describe. PHPStan already infers the type of each constant from its value. This PR removes these tags. It matches what core does almost everywhere: 174define()docblocks in core have no@vartag, and 17 have one.I tested two other options, and neither works:
@var bool $DOING_CRONpasses PHPStan, but it names a variable that does not exist.@var bool DOING_CRONstill reports the error.The
CUSTOM_TAGStag was also wrong. It saidarray[]|false, but the constant is a boolean flag, and core only checks! CUSTOM_TAGS. The docblock now says to define the constant astrueto use the custom tag globals.Inline
@vartags inWP_Query(9 errors)These
/** @var WP_Post[] */style tags sit above assignments to$this->posts,$this->post,$this->commentsand$this->comment. r49700 added them to help IDEs. A@vartag can only name a local variable, so PHPStan ignores these tags. I tested naming the property, as in@var WP_Post[] $this->posts. PHPStan then reads the type as$thisand reports two new errors. The property docblocks already document these types, so this PR removes the inline tags.Testing
composer phpstanreports no errors.php -lpasses on every changed file.trunk.Trac ticket: https://core.trac.wordpress.org/ticket/65817
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Finding the errors, testing the fix options, editing the docblocks and baseline, and drafting the PR. I reviewed the changes.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code