Skip to content

Fix PHPStan errors with WordPress 7.1 stubs - #257

Merged
swissspidy merged 1 commit into
mainfrom
fix/phpstan-wp71
Aug 29, 2026
Merged

Fix PHPStan errors with WordPress 7.1 stubs#257
swissspidy merged 1 commit into
mainfrom
fix/phpstan-wp71

Conversation

@swissspidy

@swissspidy swissspidy commented Aug 29, 2026

Copy link
Copy Markdown
Member

php-stubs/wordpress-stubs v7.1.0 tightened a couple of WP core types, which surfaced four new PHPStan errors:

  • WP_Query::$posts is now WP_Post[]|int[]|null. The three foreach ( $images->posts ... ) loops now read the property into a local and include it in the existing "No images found." guard.
  • wp_get_attachment_metadata() now returns a precise array shape in which sizes is optional, so the @param of Media_Command::update_attachment_metadata_for_image_size() was corrected to array{sizes?: array<string, mixed>}|false.

No runtime behaviour change. composer phpstan and phpcs are clean.


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling when no image results are returned, preventing processing errors.
    • Updated image regeneration, pruning, and orientation correction to process results more reliably.
  • Documentation

    • Clarified that image size metadata is optional when updating attachment metadata.

`WP_Query::$posts` is now nullable and `wp_get_attachment_metadata()`
returns a precise array shape where `sizes` is optional.
Copilot AI lite review requested due to automatic review settings August 29, 2026 07:59
@swissspidy
swissspidy requested a review from a team as a code owner August 29, 2026 07:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added automated-pr bug command:media Related to 'media' command command:media-image-size Related to 'media image-size' command scope:testing Related to testing labels Aug 29, 2026
@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6722e199-be0f-49fa-84a8-26cfc707f3d2

📥 Commits

Reviewing files that changed from the base of the PR and between 9708085 and b66211c.

📒 Files selected for processing (1)
  • src/Media_Command.php

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The media commands now validate query post results before processing them and iterate over local post arrays. The attachment metadata docblock now allows an optional sizes key.

Changes

Media command updates

Layer / File(s) Summary
Regenerate and prune query handling
src/Media_Command.php
regenerate and prune store query posts locally, require an array of posts for the empty-result guard, and iterate over $posts.
Fix orientation query handling
src/Media_Command.php
fix_orientation applies the same local post storage, array validation, and iteration changes.
Attachment metadata contract
src/Media_Command.php
The metadata annotation marks the sizes key as optional.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to b6621

This change only adds safe handling for WordPress query results and updates a metadata type annotation, with no intended runtime or interface change. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: brianhenryie

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: fixing PHPStan errors caused by WordPress 7.1 stubs.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/phpstan-wp71

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@swissspidy swissspidy added this to the 3.0.1 milestone Aug 29, 2026
@codecov

codecov Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy
swissspidy merged commit 8ef2bf4 into main Aug 29, 2026
57 checks passed
@swissspidy
swissspidy deleted the fix/phpstan-wp71 branch August 29, 2026 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-pr bug command:media Related to 'media' command command:media-image-size Related to 'media image-size' command scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants