Repository navigation
Code Quality: Resolve the property.defaultValue PHPStan errors. - #16263
mukeshpanchal27 wants to merge 14 commits into
Conversation
`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>
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
🟡 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.propertyentries.
| 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>

Trac ticket: https://core.trac.wordpress.org/ticket/66739
Description
This PR resolves all 18
property.defaultValuePHPStan errors and deletestests/phpstan/baselines/property.defaultValue.neon.PHPStan reports
property.defaultValuewhen a property's default value does not match its documented type. In each case here the default is intended, so the@vartag is corrected to include it, as was done for the nullable caches ofWP_Theme_JSON_Resolverin r65218. The one exception isWP_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.Walker::$tree_type,Walker_Nav_Menu::$tree_typestring|string[]in the parent andstring[]inWalker_Nav_Menu, which has used an array since r13802.WP_Block::$inner_blocksWP_Block_List|array{}. It stays an empty array when the block has no inner blocks.WP_Term::$term_group0, like the other integer properties of the class, theterm_groupcolumn, and the valuesanitize_term_field()produces.$meta_queryand$date_queryofWP_Query,WP_Comment_Query,WP_Site_Query,WP_Term_Query,WP_User_QueryWP_Meta_Query|falseandWP_Date_Query|false.$meta_queryis false until the query runs, and$date_queryis false unless the query has adate_queryargument.WP_Customize_Panel::$theme_supportsstring|string[], as for sections and settings, instead ofmixed[].$active_callbackofWP_Customize_Control,WP_Customize_Panel,WP_Customize_Section@var callable|stringand@phpstan-var callable|''. The constructor replaces the empty string with the class'sactive_callback()method.$validate_callback,$sanitize_callback,$sanitize_js_callbackofWP_Customize_Setting@var callable|stringand@phpstan-var callable|''. An empty string means there is no callback.The readable type goes in
@varand the exact one in@phpstan-var, as r65791 did forWP_Theme::$update, since the literal''type is only used in@phpstan-*tags in core.Two other changes come with these:
$active_callbackable to be an empty string, PHPStan no longer reports theempty()check in each constructor as always false. Commits 10–12 also remove those three entries from theempty.propertybaseline.WP_Customize_Panel::$active_callbackwas copied fromWP_Customize_Sectionand referred to sections. Commit 11 corrects it to refer toWP_Customize_Panel::active()and the panel.Apart from the
WP_Term::$term_groupdefault, there is no runtime change. That default only applies to aWP_Termconstructed from an object without aterm_group. A final commit adds a test for it toTests_Term_WpTerm, since terms loaded from the database always provideterm_group.Testing
composer phpstan:defaultandcomposer phpstan:strictreport no errors, andcomposer phpstan:defaultpasses at each of the 13 commits.composer phpstan:baselines -- --identifier=property.defaultValue --config=phpstan.neon.distreports no errors and deletes the file.trunk.Tests_Term_WpTerm::test_term_grouppasses, and its case without aterm_groupfails with the old''default.customize,query,comment,taxonomy,user,blocks, andmenupass. The warnings intaxonomy(1) anduser(5) also appear ontrunk.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