Docs: Reconcile hash notation with the values callers pass - #13235
Docs: Reconcile hash notation with the values callers pass#13235swissspidy wants to merge 1 commit into
Conversation
Several hashes describe a narrower type than the code on either side of them uses. Where the documented type is the one that is wrong, it is widened; where the caller is, it is corrected to what the hash already says. Documentation: - `WP_Ajax_Response::add()` documents `$id` as `int|WP_Error` and `$position` as `string`. Every caller in `wp-admin` passes a numeric string for the first and an int for the second, which is what the `$position` description already describes: "Accepts 1 (bottom), -1 (top)". - `get_bookmarks()` documents `$category` as a comma-separated list of IDs. The links list table passes a single ID as an int, which `wp_parse_id_list()` accepts. - `wp_list_pages()` documents `$title_li` as `string`, in a description that says "Passing a null or empty value will result in no heading". Twenty Twenty passes `false` to get exactly that. - `wp_nav_menu()` documents `$container` as `string`, in a description that begins "Whether to wrap the ul". Twenty Twenty-One passes `false` not to. - `WP_Customize_Setting::$default` is documented as `string` and holds whatever the setting's default is. Two subclasses already redeclare it as `array`, which the analysis reported as a covariance error, and one assignment of a `stdClass` was reported as well. All three were baselined; typing the property `mixed` removes them. Call sites: - `WP_MS_Themes_List_Table` passes `'inline'` for `wp_admin_notice()`'s `$additional_classes`, which takes a list of classes. - Twenty Nineteen passes `null` for `comment_form()`'s `$title_reply`, where an empty string suppresses the heading just as well. - Twenty Twenty passes `''` for `wp_nav_menu()`'s `$fallback_cb`, which takes `callable|false`. - `WP_Customize_Manager` passes `0` for `get_pages()`'s `$hierarchical`, which takes a bool. These surfaced while teaching PHPStan to read hash notation in WordPress#13233, but each is a disagreement between a docblock and the code that stands on its own. Three baseline entries go away with them. Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com> Co-Authored-By: Claude <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. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @claude. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Several hashes describe a narrower type than the code on either side of them uses. Where the documented type is the one that is wrong, this widens it; where the caller is, it corrects the caller to what the hash already says.
These surfaced while teaching PHPStan to read hash notation in #13233, but each is a disagreement between a docblock and the code that stands on its own, so they are split out here rather than carried in that pull request's baselines.
Documentation
WP_Ajax_Response::add()$idasint|WP_Errorand$positionasstring. Every caller inwp-adminpasses a numeric string for the first and an int for the second — which is what the$positiondescription already says: "Accepts 1 (bottom), -1 (top)"get_bookmarks()$categoryas a comma-separated list of IDs. The links list table passes a single ID as an int, whichwp_parse_id_list()acceptswp_list_pages()$title_liasstring, in a description reading "Passing a null or empty value will result in no heading". Twenty Twenty passesfalseto get exactly thatwp_nav_menu()$containerasstring, in a description beginning "Whether to wrap the ul". Twenty Twenty-One passesfalsenot toWP_Customize_Setting::$defaultstringand holds whatever the setting's default is$defaultis the interesting one: two subclasses already redeclare it asarray, and one assignment of astdClassexists. All three were reported and baselined — typing the propertymixedremoves those three entries. This pull request is a net reduction in the baselines.Call sites
WP_MS_Themes_List_Table'inline'forwp_admin_notice()'s$additional_classes, which takes a list of classesnullforcomment_form()'s$title_reply, where an empty string suppresses the heading just as well''forwp_nav_menu()'s$fallback_cb, which takescallable|falseWP_Customize_Manager0forget_pages()'s$hierarchical, which takes a boolEach caller change is behaviourally identical to what it replaces — the values are already falsy or already accepted — so this is about saying the same thing in the documented type.
What is not here
The same exercise surfaced call sites that no docblock change reaches, because the array reaching them has no statically known keys — five
wp_insert_post()callers,get_pages()inpost-template.php,register_sidebar()inwidgets.php. One more,WP_Customize_Manager::get_changeset_posts(), wantsget_post_stati()to say which ofstring[]orstdClass[]it returns for a given$output, which is a separate change. Those are left alone.Testing
composer phpstanis green, from a cleared result cache, andcomposer lintreports nothing new on the changed files. The docblock realignments are column-only where a widened type changed the width.Trac ticket: https://core.trac.wordpress.org/ticket/65817
Shares a ticket with #13233 for now; happy to move it to its own.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Used for: finding these disagreements by running the analysis with #13233's extension enabled, checking each against the code, and drafting the corrections and this description.
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 by Claude Code