Skip to content

PHPStan: Fix dynamic calls to process_blocks_custom_css and enable dynamicCallOnStaticMethod rule - #87058

Merged
westonruter merged 5 commits into
WordPress:trunkfrom
noruzzamans:add/phpstan-strict-rules-dynamic-call-on-static-method
Nov 19, 2026
Merged

westonruter merged 5 commits into
WordPress:trunkfrom
noruzzamans:add/phpstan-strict-rules-dynamic-call-on-static-method

Conversation

@noruzzamans

@noruzzamans noruzzamans commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

What?

Follow up to #86460.

Replaces three dynamic $this->process_blocks_custom_css() calls with static::process_blocks_custom_css() in WP_Theme_JSON_Gutenberg, and enables the dynamicCallOnStaticMethod strict rules in phpstan.neon.dist.

Why?

WP_Theme_JSON_Gutenberg::process_blocks_custom_css() is declared public static. In three locations within WP_Theme_JSON_Gutenberg, it was being called dynamically via $this-> instead of static::.

As documented in #86460, these three calls were the only errors preventing dynamicCallOnStaticMethod from being enabled. Fixing them brings the Gutenberg codebase into full compliance and enables the strict rule by default, ensuring all static method calls and callables are invoked statically.

The equivalent calls exist in WordPress core's WP_Theme_JSON (lines 2286, 4205, 4537), which can be synced to core.

How?

  • Updates three calls to process_blocks_custom_css() in lib/class-wp-theme-json-gutenberg.php to use static:: instead of $this->:
    • In get_block_custom_css() (line 2312)
    • In get_styles_for_block() for style variations (line 4269)
    • In get_styles_for_block() for block custom CSS (line 4614)
  • Enables DynamicCallOnStaticMethodsRule and DynamicCallOnStaticMethodsCallableRule under rules: in phpstan.neon.dist.
  • Updates the local configuration example in docs/contributors/code/coding-guidelines.md to disable dynamicCallOnStaticMethod: false when a local phpstan.neon includes rules.neon.

Testing Instructions

  1. Run composer phpstan (or npm run typecheck:php). Verify analysis finishes with zero errors across all 327 analyzed files.
  2. Run vendor/bin/phpcs lib/class-wp-theme-json-gutenberg.php. Verify 0 errors and 0 warnings.
  3. In a PHP file, introduce a dynamic call to any public static method such as $this->process_blocks_custom_css(). Run composer phpstan and verify staticMethod.dynamicCall is reported.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 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: noruzzamans <noruzzaman@git.wordpress.org>
Co-authored-by: westonruter <westonruter@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.

@noruzzamans
noruzzamans marked this pull request as ready for review November 19, 2026 03:51
@noruzzamans noruzzamans self-assigned this Nov 19, 2026
@noruzzamans noruzzamans added the [Type] Code Quality Issues or PRs that relate to code quality label Nov 19, 2026
@noruzzamans noruzzamans added No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core and removed No Core Sync Required Indicates that any changes do not need to be synced to WordPress Core labels Nov 19, 2026
noruzzamans and others added 4 commits November 19, 2026 10:26
Render_Block_MediaText_Test::setup_query() is declared static but was
called as $this->setup_query(), which the dynamicCallOnStaticMethod
strict rule reports when a local phpstan.neon analyzes phpunit/.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: dd6ba841-fda3-4a15-8474-62f4e9285131
With dynamicCallOnStaticMethod enabled, a local phpstan.neon that adds
phpunit/ to the paths, as the coding guidelines describe, reported
thousands of errors, since PHPUnit declares its assertions and
markTestSkipped() static while tests call them on $this, as WordPress
core's tests do.

Register phpstan-phpunit's DynamicCallToAssertionIgnoreExtension, which
its extension.neon enables only with bleedingEdge, to ignore
$this->assert*() calls, and ignore $this->markTestSkipped() in
phpunit/. The latter entry does not report itself as unmatched, since
the default configuration does not analyze the tests.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: dd6ba841-fda3-4a15-8474-62f4e9285131
…atic-method

Resolve the conflict in the coding guidelines' local configuration
example, where trunk added numericOperandsInArithmeticOperators (from
the merged numeric operands PR) and this branch added
dynamicCallOnStaticMethod at the same spot. Keep both.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>
Claude-Code-Session-Id: dd6ba841-fda3-4a15-8474-62f4e9285131
@westonruter
westonruter merged commit 5ad22a6 into WordPress:trunk Nov 19, 2026
82 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.6 milestone Nov 19, 2026
wporg-sync pushed a commit to WordPress/wordpress-develop that referenced this pull request Nov 25, 2026
The `WP_Theme_JSON::process_blocks_custom_css()` method is declared static, yet three of its call sites invoked it through `$this` while the others already used `static::`. Behavior is unchanged, since both forms resolve the method with late static binding. In Gutenberg the same change, made in WordPress/gutenberg#87058, cleared the only errors of the `dynamicCallOnStaticMethod` rule from phpstan-strict-rules, so making it here keeps `WP_Theme_JSON` in sync with its Gutenberg counterpart.

Developed in #16093.
Follow-up to r55192, r58421.

Props noruzzaman, westonruter.
See #66739.


git-svn-id: https://develop.svn.wordpress.org/trunk@65770 602fd350-edb4-49c9-b593-d223f7449a82
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Nov 25, 2026
The `WP_Theme_JSON::process_blocks_custom_css()` method is declared static, yet three of its call sites invoked it through `$this` while the others already used `static::`. Behavior is unchanged, since both forms resolve the method with late static binding. In Gutenberg the same change, made in WordPress/gutenberg#87058, cleared the only errors of the `dynamicCallOnStaticMethod` rule from phpstan-strict-rules, so making it here keeps `WP_Theme_JSON` in sync with its Gutenberg counterpart.

Developed in WordPress/wordpress-develop#16093.
Follow-up to r55192, r58421.

Props noruzzaman, westonruter.
See #66739.

Built from https://develop.svn.wordpress.org/trunk@65770


git-svn-id: http://core.svn.wordpress.org/trunk@64799 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
…namicCallOnStaticMethod rule (WordPress#87058)

* PHPStan: Fix dynamic calls to process_blocks_custom_css and enable dynamicCallOnStaticMethod rule

* Add Core backport changelog entry for Core PR 16093

* Call the static setup_query() test helper statically

Render_Block_MediaText_Test::setup_query() is declared static but was
called as $this->setup_query(), which the dynamicCallOnStaticMethod
strict rule reports when a local phpstan.neon analyzes phpunit/.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>

* Ignore dynamic calls to PHPUnit's static assertions in tests

With dynamicCallOnStaticMethod enabled, a local phpstan.neon that adds
phpunit/ to the paths, as the coding guidelines describe, reported
thousands of errors, since PHPUnit declares its assertions and
markTestSkipped() static while tests call them on $this, as WordPress
core's tests do.

Register phpstan-phpunit's DynamicCallToAssertionIgnoreExtension, which
its extension.neon enables only with bleedingEdge, to ignore
$this->assert*() calls, and ignore $this->markTestSkipped() in
phpunit/. The latter entry does not report itself as unmatched, since
the default configuration does not analyze the tests.

Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com>

---------

Co-authored-by: noruzzamans <noruzzaman@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants