Skip to content

PHPStan: Treat IS_GUTENBERG_PLUGIN as a dynamic constant - #86093

Merged
westonruter merged 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-always-true-conditions
Nov 1, 2026
Merged

westonruter merged 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-always-true-conditions

Conversation

@huzaifaalmesbah

@huzaifaalmesbah huzaifaalmesbah commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

What?

See #86088

Adds IS_GUTENBERG_PLUGIN to PHPStan's dynamicConstantNames and removes the resolved entries from the PHPStan baseline.

Why?

lib/load.php defines IS_GUTENBERG_PLUGIN as true, so PHPStan treats the constant as always true and reports every defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN check as booleanAnd.rightAlwaysTrue.

These checks are not dead code. The block library and core-actions are copied into WordPress Core, where the constant is not defined, and the checks keep plugin-only behavior (such as the __unstableLocation feature) out of Core. Removing them would be wrong, so the fix belongs in the configuration rather than the code.

Together, these changes clear 9 of the 226 errors initially baselined in #66693.

How?

  • Added IS_GUTENBERG_PLUGIN to dynamicConstantNames in tools/phpstan/base.neon, next to MEDIA_TRASH, so PHPStan treats its value as unknown.
  • Removed the corresponding booleanAnd.rightAlwaysTrue entries from tools/phpstan/baseline.neon: lib/client-assets.php (1), navigation-link (2), navigation-submenu (3), core-actions (1), and 2 of the 3 in navigation.

No PHP source files are changed.

Testing Instructions

  1. Run composer phpstan and confirm it passes with no unmatched ignored errors.
  2. Run composer phpstan:baselines and confirm tools/phpstan/baseline.neon has no further changes.

Testing Instructions for Keyboard

Not applicable. There are no UI changes.

Screenshots or screencast

Not applicable.

Use of AI Tools

I used Claude Code to identify the affected occurrences and draft the change. I reviewed the diff and take responsibility for it.

`lib/load.php` defines `IS_GUTENBERG_PLUGIN` as `true`, so PHPStan reported every `defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN` check as always true. These checks are intentional: the block library and other packages are copied into WordPress Core, where the constant is not defined. Add the constant to `dynamicConstantNames` and remove the 9 resolved entries from the baseline.

See WordPress#86088.
@huzaifaalmesbah huzaifaalmesbah added the [Type] Code Quality Issues or PRs that relate to code quality label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: huzaifaalmesbah <huzaifaalmesbah@git.wordpress.org>

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.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@huzaifaalmesbah
huzaifaalmesbah marked this pull request as ready for review November 1, 2026 02:09
@westonruter
westonruter merged commit 99f85ca into WordPress:trunk Nov 1, 2026
118 of 120 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Nov 1, 2026
@ingeniumed ingeniumed added [Type] Build Tooling Issues or PRs related to build tooling and removed [Type] Code Quality Issues or PRs that relate to code quality labels Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants