You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Baselined PHPStan errors need to be addressed #86088
In #66693, PHPStan was integrated into the Gutenberg development tooling (issue #66598).
It is adopting rule level 5, which matches the current rule level in core (see Core-61175). These rules include:
basic checks, unknown classes, unknown functions, unknown methods called on $this, wrong number of arguments passed to those methods and functions, always undefined variables
possibly undefined variables, unknown magic methods and properties on classes with __call and __get
unknown methods checked on all expressions (not just $this), validating PHPDocs
return types, types assigned to properties
basic dead code checking - always false instanceof and other type checks, dead else branches, unreachable code after return; etc.
checking types of arguments passed to methods and functions
With each error fixed, run composer phpstan:baselines to regenerate the baseline (which is the same command used in core).
Each PR should reference this issue, so it will stay open until the final PR which removes the last error.
Note that some errors may warrant being ignored. See prior art in core's phpstan.neon.dist. Do not use @phpstan-ignore comments to suppress errors unless absolutely neccessary.
Reacted by Tom Harrigan, Himanshu Pathak and Jason Bahl
@westonruter A question before I pick up the argument.type errors.
24 of them come from passing a string to WP_HTML_Tag_Processor::next_tag(), e.g. next_tag( 'FIGURE' ). Core documents $query as array|string|null, and Core's own argument.type baseline has no next_tag entries, but the generated stubs here type it as array{tag_name?: string|null, ...}|null, so the string part seems to get lost when the hash notation is turned into an array shape.
That makes these false positives rather than code issues. Would you prefer to:
fix the stub generation so string is kept, or
add a targeted ignore for this message in phpstan.neon.dist?
I'm happy to work on either. In the meantime I'll keep going with the other argument.type errors.
4. 24 of them come from passing a string to WP_HTML_Tag_Processor::next_tag(), e.g. next_tag( 'FIGURE' ). Core documents $query as array|string|null, and Core's own argument.type baseline has no next_tag entries, but the generated stubs here type it as array{tag_name?: string|null, ...}|null, so the string part seems to get lost when the hash notation is turned into an array shape.
Yes, I see that. The stub gets generated as:
/** * Finds the next tag matching the $query. * * @since 6.2.0 * @since 6.5.0 No longer processes incomplete tokens at end of document; pauses the processor at start of token. * * @param array|string|null $query { * Optional. Which tag name to find, having which class, etc. Default is to find any tag. * * @type string|null $tag_name Which tag to find, or `null` for "any tag." * @type int|null $match_offset Find the Nth tag matching all search criteria. * 1 for "first" tag, 3 for "third," etc. * Defaults to first tag. * @type string|null $class_name Tag must contain this whole class name to match. * @type string|null $tag_closers "visit" or "skip": whether to stop on tag closers, e.g. </div>. * } * @return bool Whether a tag was matched. * * @phpstan-impure * @phpstan-param null|array{ * tag_name?: string|null, * match_offset?: int|null, * class_name?: string|null, * tag_closers?: string|null, * } $query */publicfunctionnext_tag($query = \null): bool
{
}
The string is getting incorrectly dropped. I think this stems from the stub generator thinking that string here is a query string. This relates to WordPress/wordpress-develop#13433 which seeks to add typing for that function. But here the string is not a query string, but rather just a string which is a shortcut for writing array( 'tag_name' => 'foo' ). So it looks like the stub generator is overly matching that this is a query string. cc @szepeviktor
So the stub generator should be fixed, but for this one we can also narrow the types in WP_HTML_Tag_Processor with explicit @phpstan-param tags.
Two of the remaining errors need a decision before they can be fixed:
lib/experimental/navigation-theme-opt-in.php (8 errors). The block-nav-menus opt-in was disabled in 2021 (Temporarily disable support for theme-opt for block-nav-menus from the Nav Editor #34265) with hard-coded if ( true ) / if ( false ), which causes the dead-code errors. The other 4 are menu items typed as WP_Post with extra properties, which Core also keeps in its baseline. Should this file be removed, now that the Navigation editor is gone, or should these be ignored in phpstan.neon.dist?
WP_REST_Global_Styles_Controller_Gutenberg::prepare_links() (1 error). It takes int $id while the parent takes WP_Post. Core has the same code and baseline entry, and fixing it would change the signature. Should it be ignored, or left in the baseline?
For the Tag Cloud error, I've opened a Core PR to document wp_generate_tag_cloud()'s smallest and largest as int|float, since the block passes floats: WordPress/wordpress-develop#15306
Once that's committed and the stubs are regenerated, the baseline entry for packages/block-library/src/tag-cloud/index.php can be removed.
@huzaifaalmesbah The Tag Cloud fix landed in core as r65161, from WordPress/wordpress-develop#15306. wp_generate_tag_cloud() now documents smallest and largest as int|float, so the baseline entry for packages/block-library/src/tag-cloud/index.php can be removed once the stubs are regenerated from a core version that includes it.
The commit also fixes a bug that the float type exposed: with equal float font sizes, as the block passes when its smallest and largest sizes match, an aria-label was output on every tag even though it is meant to be omitted when all tags share one size. Since render_block_core_tag_cloud() calls wp_tag_cloud(), the block gets that fix from core with no change needed in Gutenberg.
Activity
huzaifaalmesbah commentedon Nov 1, 2026
@westonruter A question before I pick up the
argument.typeerrors.24 of them come from passing a string to
WP_HTML_Tag_Processor::next_tag(), e.g.next_tag( 'FIGURE' ). Core documents$queryasarray|string|null, and Core's ownargument.typebaseline has nonext_tagentries, but the generated stubs here type it asarray{tag_name?: string|null, ...}|null, so thestringpart seems to get lost when the hash notation is turned into an array shape.That makes these false positives rather than code issues. Would you prefer to:
stringis kept, orphpstan.neon.dist?I'm happy to work on either. In the meantime I'll keep going with the other
argument.typeerrors.Navigation: Use self:: to access private static members (#86090)
PHPStan: Treat IS_GUTENBERG_PLUGIN as a dynamic constant (#86093)
Block Library: Return values matching the documented types instead of…
Block supports: Drop the isset() check on WP_Block_Type::$selectors
westonruter commentedon Nov 1, 2026
@huzaifaalmesbah:
Yes, I see that. The stub gets generated as:
The
stringis getting incorrectly dropped. I think this stems from the stub generator thinking thatstringhere is a query string. This relates to WordPress/wordpress-develop#13433 which seeks to add typing for that function. But here thestringis not a query string, but rather just a string which is a shortcut for writingarray( 'tag_name' => 'foo' ). So it looks like the stub generator is overly matching that this is a query string. cc @szepeviktorSo the stub generator should be fixed, but for this one we can also narrow the types in
WP_HTML_Tag_Processorwith explicit@phpstan-paramtags.I'll take this.
Fix invalid PHPDoc tags reported by PHPStan (#86092)
westonruter commentedon Nov 1, 2026
See:
next_tag()string query false positives and quiet the stubs generator #86109Theme JSON: Use self:: to call private static methods (#86096)
huzaifaalmesbah commentedon Nov 1, 2026
Two of the remaining errors need a decision before they can be fixed:
lib/experimental/navigation-theme-opt-in.php(8 errors). The block-nav-menus opt-in was disabled in 2021 (Temporarily disable support for theme-opt forblock-nav-menusfrom the Nav Editor #34265) with hard-codedif ( true )/if ( false ), which causes the dead-code errors. The other 4 are menu items typed asWP_Postwith extra properties, which Core also keeps in its baseline. Should this file be removed, now that the Navigation editor is gone, or should these be ignored inphpstan.neon.dist?WP_REST_Global_Styles_Controller_Gutenberg::prepare_links()(1 error). It takesint $idwhile the parent takesWP_Post. Core has the same code and baseline entry, and fixing it would change the signature. Should it be ignored, or left in the baseline?huzaifaalmesbah commentedon Nov 1, 2026
For the Tag Cloud error, I've opened a Core PR to document
wp_generate_tag_cloud()'ssmallestandlargestasint|float, since the block passes floats: WordPress/wordpress-develop#15306Once that's committed and the stubs are regenerated, the baseline entry for
packages/block-library/src/tag-cloud/index.phpcan be removed.Remove redundant truthiness checks after ! empty() (#86094)
westonruter commentedon Nov 1, 2026
🤖 Comment by Claude Opus 5.5 · medium effort
@huzaifaalmesbah The Tag Cloud fix landed in core as r65161, from WordPress/wordpress-develop#15306.
wp_generate_tag_cloud()now documentssmallestandlargestasint|float, so the baseline entry forpackages/block-library/src/tag-cloud/index.phpcan be removed once the stubs are regenerated from a core version that includes it.The commit also fixes a bug that the float type exposed: with equal float font sizes, as the block passes when its smallest and largest sizes match, an
aria-labelwas output on every tag even though it is meant to be omitted when all tags share one size. Sincerender_block_core_tag_cloud()callswp_tag_cloud(), the block gets that fix from core with no change needed in Gutenberg.Sync three small PHPStan fixes from Core (#86099)
Comment Author Avatar: Pass the avatar size to get_avatar()
Comment Author Avatar: Pass the avatar size to get_avatar() (#86113)
Fix PHPStan errors in the WordPress 7.1 and 7.2 compat shims
Fix PHPStan errors in the WordPress 7.1 and 7.2 compat shims (#86100)
Block Library: Fix argument types reported by PHPStan (#86095)
Block Library: Fix small PHPStan errors in several blocks (#86101)
Collaboration: Return a WP_REST_Response from the sync save handler (#…
Theme JSON, Duotone: Fix return types and docblocks reported by PHPSt…
PHPStan: Resolve always-true type checks (#86104)
Style Engine, Navigation: Fix docblocks reported by PHPStan
Style Engine, Navigation: Fix docblocks reported by PHPStan (#86105)
westonruter commentedon Nov 7, 2026
The final two PRs to resolve the remaining handful for PHPStan level 5 errors which are ready for review:
The second has a core backport to review as well:
westonruter commentedon Nov 10, 2026
With the merging of #86470, the baseline is now empty at PHPStan error level 5!
gutenberg/tools/phpstan/baseline.neon
Lines 1 to 2 in 29bc9ed