Skip to content

Code Quality: Resolve the property.defaultValue PHPStan errors. - #16263

Open
mukeshpanchal27 wants to merge 14 commits into
WordPress:trunkfrom
mukeshpanchal27:fix/property-default-value-baseline
Open

mukeshpanchal27 wants to merge 14 commits into
WordPress:trunkfrom
mukeshpanchal27:fix/property-default-value-baseline

Conversation

@mukeshpanchal27

@mukeshpanchal27 mukeshpanchal27 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/66739

Description

This PR resolves all 18 property.defaultValue PHPStan errors and deletes tests/phpstan/baselines/property.defaultValue.neon.

PHPStan reports property.defaultValue when a property's default value does not match its documented type. In each case here the default is intended, so the @var tag is corrected to include it, as was done for the nullable caches of WP_Theme_JSON_Resolver in r65218. The one exception is WP_Term::$term_group, whose empty string default was a mistake.

There is one commit per class, so each can be reviewed or committed on its own, plus a test commit. Every commit passes composer phpstan:default.

Commit Property Change
1 Walker::$tree_type, Walker_Nav_Menu::$tree_type string|string[] in the parent and string[] in Walker_Nav_Menu, which has used an array since r13802.
2 WP_Block::$inner_blocks WP_Block_List|array{}. It stays an empty array when the block has no inner blocks.
3 WP_Term::$term_group The default is now 0, like the other integer properties of the class, the term_group column, and the value sanitize_term_field() produces.
4–8 $meta_query and $date_query of WP_Query, WP_Comment_Query, WP_Site_Query, WP_Term_Query, WP_User_Query WP_Meta_Query|false and WP_Date_Query|false. $meta_query is false until the query runs, and $date_query is false unless the query has a date_query argument.
9 WP_Customize_Panel::$theme_supports string|string[], as for sections and settings, instead of mixed[].
10–12 $active_callback of WP_Customize_Control, WP_Customize_Panel, WP_Customize_Section @var callable|string and @phpstan-var callable|''. The constructor replaces the empty string with the class's active_callback() method.
13 $validate_callback, $sanitize_callback, $sanitize_js_callback of WP_Customize_Setting @var callable|string and @phpstan-var callable|''. An empty string means there is no callback.

The readable type goes in @var and the exact one in @phpstan-var, as r65791 did for WP_Theme::$update, since the literal '' type is only used in @phpstan-* tags in core.

Two other changes come with these:

  • With $active_callback able to be an empty string, PHPStan no longer reports the empty() check in each constructor as always false. Commits 10–12 also remove those three entries from the empty.property baseline.
  • The docblock of WP_Customize_Panel::$active_callback was copied from WP_Customize_Section and referred to sections. Commit 11 corrects it to refer to WP_Customize_Panel::active() and the panel.

Apart from the WP_Term::$term_group default, there is no runtime change. That default only applies to a WP_Term constructed from an object without a term_group. A final commit adds a test for it to Tests_Term_WpTerm, since terms loaded from the database always provide term_group.

Testing

  • composer phpstan:default and composer phpstan:strict report no errors, and composer phpstan:default passes at each of the 13 commits.
  • composer phpstan:baselines -- --identifier=property.defaultValue --config=phpstan.neon.dist reports no errors and deletes the file.
  • PHPCS reports the same results on the 13 changed files as on trunk.
  • Tests_Term_WpTerm::test_term_group passes, and its case without a term_group fails with the old '' default.
  • PHPUnit groups customize, query, comment, taxonomy, user, blocks, and menu pass. The warnings in taxonomy (1) and user (5) also appear on trunk.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Tracing the history of each property, writing the docblock changes, running PHPStan, PHPCS and PHPUnit, and drafting the commit messages and this description. 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 13 commits November 26, 2026 15:49
`Walker_Nav_Menu` has set `$tree_type` to an array of the item types it handles since r13802, but both it and `Walker` documented the property as a string. The parent now allows a string or an array of strings, and `Walker_Nav_Menu` documents its array. This removes the `Walker_Nav_Menu` entry from the `property.defaultValue` baseline. There is no runtime change.

Follow-up to r13802, r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since `WP_Block` was introduced in r48159, `$inner_blocks` has defaulted to an empty array, and `refresh_parsed_block_dependents()` only replaces it with a `WP_Block_List` when the parsed block has inner blocks. Its `@var` tag omitted the empty array. It is now documented as `WP_Block_List|array{}`, which removes the `WP_Block` entry from the `property.defaultValue` baseline. There is no runtime change.

Follow-up to r48159, r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since `WP_Term` was introduced in r34997, `$term_group` has been documented as an integer, but it defaulted to an empty string. The other integer properties of the class default to `0`, as does the `term_group` column, and `sanitize_term_field()` casts the value to an integer. The default is now `0`, which removes the `WP_Term` entry from the `property.defaultValue` baseline.

This only affects a `WP_Term` constructed from an object without a `term_group`, since the constructor copies every property it is given.

Follow-up to r34997, r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… false.

`WP_Query::$meta_query` and `WP_Query::$date_query` default to false. `get_posts()` only sets `$meta_query` to a `WP_Meta_Query` when the query runs, and only sets `$date_query` to a `WP_Date_Query` when the query has a `date_query` argument, but their `@var` tags omitted false. Adding it removes two entries from the `property.defaultValue` baseline. There is no runtime change.

Follow-up to r25139, r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…possibly false.

`WP_Comment_Query::$meta_query` and `WP_Comment_Query::$date_query` default to false. `get_comments()` only sets `$meta_query` to a `WP_Meta_Query` when the query runs, and `get_comment_ids()` only sets `$date_query` to a `WP_Date_Query` when the query has a `date_query` argument, but their `@var` tags omitted false. Adding it removes two entries from the `property.defaultValue` baseline. There is no runtime change.

Follow-up to r25139, r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sibly false.

`WP_Site_Query::$meta_query` and `WP_Site_Query::$date_query` default to false. `get_sites()` only sets `$meta_query` to a `WP_Meta_Query` when the query runs, and `get_site_ids()` only sets `$date_query` to a `WP_Date_Query` when the query has a `date_query` argument, but their `@var` tags omitted false. Adding it removes two entries from the `property.defaultValue` baseline. There is no runtime change.

Follow-up to r37477, r43010, r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`WP_Term_Query::$meta_query` defaults to false, and `get_terms()` only sets it to a `WP_Meta_Query` when the query runs, but its `@var` tag omitted false. Adding it removes the `WP_Term_Query` entry from the `property.defaultValue` baseline. There is no runtime change.

Follow-up to r37572, r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`WP_User_Query::$meta_query` defaults to false, and `prepare_query()` only sets it to a `WP_Meta_Query` when the query is prepared, but its `@var` tag omitted false. Adding it removes the `WP_User_Query` entry from the `property.defaultValue` baseline. There is no runtime change.

Follow-up to r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`WP_Customize_Panel::$theme_supports` defaults to an empty string, and `check_capabilities()` casts it to an array before passing it to `current_theme_supports()`, but it was documented as `mixed[]`. It is now documented as a string or an array of strings, as `WP_Customize_Section::$theme_supports` and `WP_Customize_Setting::$theme_supports` already are, along with the matching constructor argument. This removes the `theme_supports` entry from the `property.defaultValue` baseline. There is no runtime change.

Follow-up to r29487, r53877, r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…callback`.

`WP_Customize_Control::$active_callback` defaults to an empty string, which the constructor replaces with `WP_Customize_Control::active_callback()`, but it was documented as a callable only. The `@var` tag now includes the string, with an `@phpstan-var` tag for the exact `callable|''` type, and the description says what the empty string means. This removes the `WP_Customize_Control` entry from the `property.defaultValue` baseline. Since the `empty()` check in the constructor is no longer seen as always false, this also removes the matching entry from the `empty.property` baseline. There is no runtime change.

Follow-up to r29051, r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…llback`.

`WP_Customize_Panel::$active_callback` defaults to an empty string, which the constructor replaces with `WP_Customize_Panel::active_callback()`, but it was documented as a callable only. The `@var` tag now includes the string, with an `@phpstan-var` tag for the exact `callable|''` type, and the description says what the empty string means. This removes the `active_callback` entry for `WP_Customize_Panel` from the `property.defaultValue` baseline. Since the `empty()` check in the constructor is no longer seen as always false, this also removes the matching entry from the `empty.property` baseline. There is no runtime change.

The docblock was copied from `WP_Customize_Section` and still referred to sections. It now refers to `WP_Customize_Panel::active()` and the panel instance that the callback receives.

Follow-up to r30102, r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…callback`.

`WP_Customize_Section::$active_callback` defaults to an empty string, which the constructor replaces with `WP_Customize_Section::active_callback()`, but it was documented as a callable only. The `@var` tag now includes the string, with an `@phpstan-var` tag for the exact `callable|''` type, and the description says what the empty string means. This removes the `WP_Customize_Section` entry from the `property.defaultValue` baseline. Since the `empty()` check in the constructor is no longer seen as always false, this also removes the matching entry from the `empty.property` baseline. There is no runtime change.

Follow-up to r30102, r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…backs.

`WP_Customize_Setting::$validate_callback`, `$sanitize_callback`, and `$sanitize_js_callback` default to an empty string, which means there is no callback: the constructor only hooks each one when it is set. They were documented as callables only. Their `@var` tags now include the string, with `@phpstan-var` tags for the exact `callable|''` type, and the descriptions say what the empty string means. This empties the `property.defaultValue` baseline, so it is removed. There is no runtime change.

Follow-up to r37476, r63022.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

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.

@mukeshpanchal27
mukeshpanchal27 marked this pull request as ready for review November 26, 2026 12:45
@github-actions

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 or WordPress.org 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.

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.

🟡 Changes recommended

A regression test is missing for constructing a term without term_group and confirming it defaults to integer 0; existing database-backed tests do not cover this behavior.

1 open issue
What changed in this PR

This PR addresses 18 PHPStan property.defaultValue errors by aligning WordPress core property documentation with intended defaults. The only runtime change sets WP_Term::$term_group to integer 0.

Changes:

  • Correct property types for walkers, blocks, query containers, and Customizer callbacks.
  • Correct the panel callback documentation and the term-group default.
  • Delete the resolved default-value baseline and remove three obsolete empty.property entries.
File Description
tests/​phpstan/​baselines/​property.defaultValue.neon Deletes the baseline for all 18 resolved errors.
tests/​phpstan/​baselines/​empty.property.neon Removes three obsolete callback-check suppressions.
src/​wp-includes/​class-wp-walker.php Documents string and array tree types.
src/​wp-includes/​class-wp-user-query.php Documents the false metadata-query default.
src/​wp-includes/​class-wp-term.php Changes the term-group default to integer 0.
src/​wp-includes/​class-wp-term-query.php Documents the false metadata-query default.
src/​wp-includes/​class-wp-site-query.php Documents false metadata and date-query defaults.
src/​wp-includes/​class-wp-query.php Documents false metadata and date-query defaults.
src/​wp-includes/​class-wp-customize-setting.php Documents empty-string callback defaults.
src/​wp-includes/​class-wp-customize-section.php Clarifies the active callback’s default and type.
src/​wp-includes/​class-wp-customize-panel.php Updates theme-support types and corrects callback documentation.
src/​wp-includes/​class-wp-customize-control.php Clarifies the active callback’s default and type.
src/​wp-includes/​class-wp-comment-query.php Documents false metadata and date-query defaults.
src/​wp-includes/​class-wp-block.php Includes the empty-array inner-blocks default in its type.
src/​wp-includes/​class-walker-nav-menu.php Documents the array tree type.

Review effort: Balanced

* @var int
*/
public $term_group = '';
public $term_group = 0;
The existing tests only read `term_group` from terms loaded from the database, which always provide it. The new test constructs a `WP_Term` from an object without a `term_group` and checks that it defaults to the integer `0`, and that a provided value is kept.

Follow-up to a04b85c.

See #66739.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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