Repository navigation
Conversation
|
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:
|
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. |
There was a problem hiding this comment.
🟡 Changes recommended
PHP converts numeric category slugs to integer array keys, so the registry annotations must allow int|string keys and the baseline must be regenerated.
1 open issue
What changed in this PR
This PR addresses the remaining strict PHPStan return.type error in the ability categories registry without changing runtime behavior.
Changes:
- Documents the registry property as a string-keyed array to match the method’s return annotation.
- Deletes the strict
return.typebaseline.
| File | Description |
|---|---|
tests/phpstan/baselines-strict/return.type.neon |
Removes the strict return-type suppression. |
src/wp-includes/abilities-api/class-wp-ability-categories-registry.php |
Updates the property’s PHPDoc key type. |
Review effort: Balanced
lancewillett
left a comment
There was a problem hiding this comment.
Could you widen the return annotation on get_all_registered() instead? I registered the valid slugs '123', '007' and 'tools' through wp_register_ability_category(). The public getter returned the integer key 123 and the string keys '007' and 'tools'. A caller iterating those keys can receive either type.
I kept the existing property annotation, changed the method to @return array<array-key, WP_Ability_Category>, and removed the same baseline. Strict PHPStan passed with that change.
AI review · gpt-6.2-astra
…s annotations. Numeric slugs such as `123` pass the slug validation and PHP stores them under integer keys.
…ray-key. Numeric slugs such as `123` are stored under integer keys, so the keys can be integers or strings. The property annotation is left as it was.
|
Thanks @lancewillett, fixed in ddf52b7. |
lancewillett
left a comment
There was a problem hiding this comment.
Verified the revised getter annotation against the public registry. It covers both the integer key for '123' and the string key for '007'. Strict PHPStan passes with the baseline removed. Thanks for keeping the fix to the getter.
AI review · gpt-6.2-astra

This resolves the last strict
return.typePHPStan error and removes its baseline. Only a docblock changes; there is no runtime change.The error
WP_Ability_Categories_Registry::get_all_registered()is documented as returningarray<string, WP_Ability_Category>, but it returns$this->registered_categories, which is documented asWP_Ability_Category[]. At level 10 PHPStan does not accept that array, whose keys are of any type, as one keyed by string, and reportsshould return array<string, WP_Ability_Category> but returns array<WP_Ability_Category>.The fix
The slug check in
register()(/^[a-z0-9]+(?:-[a-z0-9]+)*$/) accepts all-numeric slugs such as'123', and PHP stores those under integer keys ($this->registered_categories[ $slug ] = $category;). The keys can therefore be integers or strings, so thestringkey in the return annotation was too narrow. The@returnofget_all_registered()is nowarray<array-key, WP_Ability_Category>, which matches the property. The property docblock is unchanged. The@returnwas added in r61032.Thanks to the review comments for pointing out the numeric slug case; an earlier revision documented the property as string-keyed.
Testing
composer phpstan:defaultandcomposer phpstan:strictreport no errors.composer phpstan:baselines -- --identifier=return.type --config=phpstan-strict.neon.distreports no errors, sotests/phpstan/baselines-strict/return.type.neonis deleted. The defaultreturn.typebaseline is unchanged.class-wp-ability-categories-registry.php.vendor/bin/phpunit --group abilities-apipasses (1146 tests).Follow-up to r61032, r65668.
Trac ticket: https://core.trac.wordpress.org/ticket/66739
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.
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.