Skip to content

Code Quality: Fix the varTag.noVariable PHPStan errors and remove the baseline - #15449

Open
mukeshpanchal27 wants to merge 2 commits into
WordPress:trunkfrom
mukeshpanchal27:fix/vartag-novariable-baseline
Open

mukeshpanchal27 wants to merge 2 commits into
WordPress:trunkfrom
mukeshpanchal27:fix/vartag-novariable-baseline

Conversation

@mukeshpanchal27

Copy link
Copy Markdown
Member

This PR fixes all 17 varTag.noVariable errors and deletes tests/phpstan/baselines/varTag.noVariable.neon. There is no runtime change.

PHPStan reports varTag.noVariable when a @var tag 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.

@var tags above define() 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) and xmlrpc.php.

A @var tag above a define() 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: 174 define() docblocks in core have no @var tag, and 17 have one.

I tested two other options, and neither works:

  • A fake name such as @var bool $DOING_CRON passes PHPStan, but it names a variable that does not exist.
  • @var bool DOING_CRON still reports the error.

The CUSTOM_TAGS tag was also wrong. It said array[]|false, but the constant is a boolean flag, and core only checks ! CUSTOM_TAGS. The docblock now says to define the constant as true to use the custom tag globals.

Inline @var tags in WP_Query (9 errors)

These /** @var WP_Post[] */ style tags sit above assignments to $this->posts, $this->post, $this->comments and $this->comment. r49700 added them to help IDEs. A @var tag 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 $this and reports two new errors. The property docblocks already document these types, so this PR removes the inline tags.

Testing

  • composer phpstan reports no errors.
  • php -l passes on every changed file.
  • PHPCS reports the same warnings on the changed files as on 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

mukeshpanchal27 and others added 2 commits November 4, 2026 13:48
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>
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

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:

Props mukesh27.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@mukeshpanchal27 mukeshpanchal27 self-assigned this Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 @var annotations above define() calls.
  • Removes unsupported inline @var annotations from WP_Query property assignments.
  • Corrects the CUSTOM_TAGS documentation.
  • 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

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.

2 participants