Skip to content

Code Quality: Resolve the offsetAccess.nonOffsetAccessible PHPStan errors. - #16240

Open
mukeshpanchal27 wants to merge 1 commit into
WordPress:trunkfrom
mukeshpanchal27:fix/offset-access-nonoffsetaccessible-baseline
Open

mukeshpanchal27 wants to merge 1 commit into
WordPress:trunkfrom
mukeshpanchal27:fix/offset-access-nonoffsetaccessible-baseline

Conversation

@mukeshpanchal27

Copy link
Copy Markdown
Member

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

Description

This PR resolves all 5 offsetAccess.nonOffsetAccessible PHPStan errors and deletes tests/phpstan/baselines/offsetAccess.nonOffsetAccessible.neon.

All five errors have one cause. WP_Theme::$update was documented as @var bool, but get_theme_updates() stores the theme's update data array in it:

$update_themes[ $stylesheet ]->update = $data;

Callers then read ->update['new_version'] from that array. PHPStan trusted the bool type and reported each read as Cannot access offset 'new_version' on bool:

  • 4 in src/wp-admin/includes/class-wp-debug-data.php
  • 1 in src/wp-admin/update-core.php

Only two places assign the property:

Where Value
WP_MS_Themes_List_Table::prepare_items() true
get_theme_updates() The update data array from the update_themes transient

The property is now documented as bool|array<string, mixed>, which covers both. The docblock also says that get_theme_updates() sets it to the update data, with a @see tag. No runtime code changes.

Testing

  • composer phpstan:baselines -- --identifier=offsetAccess.nonOffsetAccessible --config=phpstan.neon.dist reports that no errors remain and deletes the file.
  • composer phpstan:default and composer phpstan:strict both report no errors.
  • PHPCS reports no errors in class-wp-theme.php. The one warning, on line 387, is on an unchanged line and also appears on trunk.

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

`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>
@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.

@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.

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.

🟢 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 $update as bool|array<string, mixed> and explains that get_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

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