Repository navigation
Code Quality: Resolve the offsetAccess.nonOffsetAccessible PHPStan errors. - #16240
mukeshpanchal27 wants to merge 1 commit into
Conversation
`get_theme_updates()` stores the theme's update data array in `WP_Theme::$update`, but the property was documented as `bool`. PHPStan therefore reported every read of `->update['new_version']` as `offsetAccess.nonOffsetAccessible`. Document the property as `bool|array<string, mixed>`, which covers both the `true` set by `WP_MS_Themes_List_Table` and the array set by `get_theme_updates()`. This resolves all five errors and removes the `offsetAccess.nonOffsetAccessible` baseline. See #66739. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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.
🟢 Approval recommended
No active review issues are reported for the documented type correction and related PHPStan baseline removal.
No open issues 🎉
What changed in this PR
This PR corrects the documented type of WP_Theme::$update to reflect its existing usage, resolving five PHPStan offset-access errors without changing runtime behavior.
Changes:
- Documents
$updateasbool|array<string, mixed>and explains thatget_theme_updates()supplies update data. - Deletes the PHPStan baseline for the five resolved errors.
| File | Description |
|---|---|
tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon |
Removes the baseline suppressing the resolved errors. |
src/wp-includes/class-wp-theme.php |
Corrects the property’s documented type and adds a function reference. |
Review effort: Balanced
Trac ticket: https://core.trac.wordpress.org/ticket/66739
Description
This PR resolves all 5
offsetAccess.nonOffsetAccessiblePHPStan errors and deletestests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon.All five errors have one cause.
WP_Theme::$updatewas documented as@var bool, butget_theme_updates()stores the theme's update data array in it:Callers then read
->update['new_version']from that array. PHPStan trusted thebooltype and reported each read asCannot access offset 'new_version' on bool:src/wp-admin/includes/class-wp-debug-data.phpsrc/wp-admin/update-core.phpOnly two places assign the property:
WP_MS_Themes_List_Table::prepare_items()trueget_theme_updates()update_themestransientThe property is now documented as
bool|array<string, mixed>, which covers both. The docblock also says thatget_theme_updates()sets it to the update data, with a@seetag. No runtime code changes.Testing
composer phpstan:baselines -- --identifier=offsetAccess.nonOffsetAccessible --config=phpstan.neon.distreports that no errors remain and deletes the file.composer phpstan:defaultandcomposer phpstan:strictboth report no errors.class-wp-theme.php. The one warning, on line 387, is on an unchanged line and also appears ontrunk.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Finding the cause of the errors, editing the docblock, running PHPStan and PHPCS, and drafting this PR. 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