Skip to content

Theme JSON: Use self:: to call private static methods - #86096

Merged
westonruter merged 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-theme-json-self-access
Nov 1, 2026
Merged

westonruter merged 1 commit into
WordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-theme-json-self-access

Conversation

@huzaifaalmesbah

@huzaifaalmesbah huzaifaalmesbah commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

What?

See #86088

Replaces static:: with self:: where WP_Theme_JSON_Gutenberg and WP_Theme_JSON_Resolver_Gutenberg call their own private static methods, and removes the resolved entries from the PHPStan baseline.

This is a backport of WordPress Core r63368 and r63384 (see Core-65817).

Why?

PHPStan reports calls to private methods through static:: as unsafe (staticClassAccess.privateMethod): late static binding resolves static:: against the called class, where a private method is not visible. Since a subclass can never supply a private method, self:: is the accurate reference and behaves identically.

WordPress Core already made this change in WP_Theme_JSON and WP_Theme_JSON_Resolver, so the Gutenberg classes were out of sync with Core. Together, these changes clear 37 of the 226 errors initially baselined in #66693.

How?

  • lib/class-wp-theme-json-gutenberg.php: 14 private static methods, 29 call sites, plus the docblock example on compute_spacing_sizes(), which Core updated as well.
  • lib/class-wp-theme-json-resolver-gutenberg.php: 5 private static methods, 8 call sites.
  • static:: is kept wherever it targets a protected or public method (such as to_ruleset() or compute_style_properties()), where late static binding is meaningful, matching Core.
  • Removed the 37 corresponding staticClassAccess.privateMethod entries from tools/phpstan/baseline.neon.

The 6 assign.propertyType errors in WP_Theme_JSON_Resolver_Gutenberg are left as they are, since Core still has the same entries in its baseline.

No Core backport is needed, since the change already exists in Core.

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.
  3. Run the theme.json PHP unit tests: npm run test:php -- --filter WP_Theme_JSON.

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.

`WP_Theme_JSON_Gutenberg` and `WP_Theme_JSON_Resolver_Gutenberg` called their private static methods through `static::`, which PHPStan reports as unsafe since a subclass cannot see private members. Use `self::` instead, which is behavior-identical. `static::` is kept where it targets protected or public methods.

This syncs the changes from WordPress Core r63368 and r63384. Remove the 37 resolved entries from the PHPStan baseline.

See WordPress#86088.
@huzaifaalmesbah huzaifaalmesbah added [Type] Code Quality Issues or PRs that relate to code quality Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core labels 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:33

@westonruter westonruter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These same changes were already applied to core in WordPress/wordpress-develop@4a8a86b and WordPress/wordpress-develop@b915feb

@westonruter
westonruter merged commit 32a259f into WordPress:trunk Nov 1, 2026
118 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Nov 1, 2026
@ingeniumed ingeniumed added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport from WordPress Core Pull request that needs to be backported to a Gutenberg release from WordPress Core Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants