Skip to content

Fix PHPStan errors with WordPress 7.1 stubs - #650

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

Fix PHPStan errors with WordPress 7.1 stubs#650
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 the types of several WordPress core functions, which surfaced 23 new PHPStan errors.

  • get_sites() and get_terms() gained conditional return types, so Site_Command::get_sites_iterator() and Term_Command::list_() now pin count/fields to the query defaults they already relied on. Both keys are stripped from the query args before that anyway, so nothing changes at runtime.
  • WP_Query::$posts is now nullable and WP_Comment_Query::query() returns non-negative ints, so the annotations in Post_Command and Comment_Command were corrected.
  • wp_insert_term() wants a non-negative parent and wp_delete_term() a non-empty $taxonomy; Term_Command::migrate() now validates with taxonomy_exists() (equivalent to the get_taxonomy() check it replaces) and passes the taxonomy name straight through.
  • Dropped two @phpstan-ignore method.deprecated comments that no longer match, and the Icons API class.notFound/function.notFound entries now that the stubs cover it. The WPCompat entries for the version-gated wp icon commands were extended to the methods that only became visible with those stubs.

Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved post listing when no posts are returned.
    • Ensured site and term listings consistently return complete records.
    • Improved term migration validation and ID handling.
  • Refactor
    • Updated compatibility checks for icon-related commands.
    • Refined internal type handling and static analysis annotations.
    • Simplified session handling checks without changing runtime behavior.

@swissspidy
swissspidy requested a review from a team as a code owner August 29, 2026 08:07
Copilot AI lite review requested due to automatic review settings August 29, 2026 08:07

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 command:comment Related to 'comment' command command:icon Related to 'icon' command command:post Related to 'post' command command:site Related to 'site' command command:term Related to 'term' 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: d255a473-b9b8-447c-91fc-3712c8596591

📥 Commits

Reviewing files that changed from the base of the PR and between 557cc00 and 5576bfa.

📒 Files selected for processing (6)
  • phpstan.neon.dist
  • src/Comment_Command.php
  • src/Post_Command.php
  • src/Site_Command.php
  • src/Term_Command.php
  • src/User_Session_Command.php
💤 Files with no reviewable changes (1)
  • src/User_Session_Command.php

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The changes refine PHPStan annotations, expand icon registry method suppressions, normalize post and site query results, request complete term objects, and update term generation and migration taxonomy handling.

Changes

Command data contracts

Layer / File(s) Summary
Static-analysis contract refinements
phpstan.neon.dist, src/Comment_Command.php, src/User_Session_Command.php
PHPStan icon registry suppressions now cover all invoked methods. Comment collection annotations use bounded integer and object-array types. Obsolete session method suppressions were removed.
Query result normalization
src/Post_Command.php, src/Site_Command.php, src/Term_Command.php
Post listing uses empty arrays for null query posts. Site iteration forces object results. Term listing requests complete WP_Term objects.
Term generation and migration handling
src/Term_Command.php
Generated previous term IDs are normalized with absint(). Migration validates and uses the original taxonomy for term lookup, deletion, and messaging.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 5576b

This PR corrects WordPress 7.1 type annotations and preserves the existing taxonomy validation and migration behavior. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: copilot

🚥 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 and concisely describes the main change: resolving PHPStan errors caused by the WordPress 7.1 stubs.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (1 skipped: 1 u…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 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.

php-stubs/wordpress-stubs v7.1.0 tightened the types of get_sites(),
get_terms(), wp_insert_term(), wp_delete_term(), WP_Query::$posts and
WP_Comment_Query::query(), and it now covers the Icons API.
@swissspidy swissspidy added this to the 3.0.3 milestone Aug 29, 2026
@swissspidy
swissspidy merged commit 77d6472 into main Aug 29, 2026
58 checks passed
@swissspidy
swissspidy deleted the fix/phpstan-wp71 branch August 29, 2026 08:58
@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:comment Related to 'comment' command command:icon Related to 'icon' command command:post Related to 'post' command command:site Related to 'site' command command:term Related to 'term' command scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants