Skip to content

Fix PHPStan errors from get_flag_value() returning bool|null - #263

Merged
swissspidy merged 1 commit into
mainfrom
claude/adoring-sagan-yqb09i
Oct 7, 2026
Merged

swissspidy merged 1 commit into
mainfrom
claude/adoring-sagan-yqb09i

Conversation

@swissspidy

@swissspidy swissspidy commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

PHPStan now infers a more precise return type for Utils\get_flag_value() through the dynamic return type extension in wp-cli/wp-cli-tests. That type is the flag's type unioned with the default's type, so boolean flags read with no default came back as bool|null. Six call sites then failed to type-check, because the values are passed to methods that expect bool (failing run).

This PR passes an explicit false default for the boolean flags skip-delete, only-missing, delete-unknown, update-attachment-refs, remove-abandoned and dry-run. There is no behavior change: a missing flag used to be null and is now false, and both are falsy everywhere they're used.

Verified locally: composer phpstan reports the same 6 errors on main and none with this change. composer phpcs is clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NDYX767HJCpR3xuCfhBTDm


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Media management commands now consistently treat optional switches as off when they are not provided. This applies to options for skipping deletion, processing only missing items, deleting unknown items, updating attachment references, removing abandoned items, and running in dry-run mode. Explicitly provided options continue to control the corresponding behavior.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 15:17
@swissspidy
swissspidy requested a review from a team as a code owner October 7, 2026 15:17

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.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 89d3e427-4d39-422a-8fb5-41014680c4c6
📥 Commits

Reviewing files that changed from the base of the PR and between 309fb12 and ba629d7.

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

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


📝 Walkthrough

Walkthrough

Four media command methods now pass false as the default when reading selected boolean flags. Existing flag precedence and cleanup conditions remain unchanged.

Changes

Boolean Flag Defaults

Layer / File(s) Summary
Set explicit defaults for command flags
src/Media_Command.php
regenerate(), prune(), replace(), and fix_orientation() now pass false as the default for selected boolean flags. Existing flag precedence and cleanup conditions remain unchanged.

Priority: ⬇️ Low

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

Change: Refactor

Suggested reviewers: schlessera

Merge Risk: ⚪ Minimal · up to ba629

The explicit defaults preserve behavior when flags are omitted while addressing the boolean type inference. No actionable merge-blocking risk remains.

🚥 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 get_flag_value() returning bool|null. It is concise and specific.
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
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions github-actions Bot added automated-pr bug command:media-import Related to 'media import' command command:media-prune Related to 'media prune' command command:media-regenerate Related to 'media regenerate' command labels Oct 7, 2026
@swissspidy swissspidy added this to the 3.1.1 milestone Oct 7, 2026
@codecov

codecov Bot commented Oct 7, 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 00c37c7 into main Oct 7, 2026
57 checks passed
@swissspidy
swissspidy deleted the claude/adoring-sagan-yqb09i branch October 7, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-pr bug command:media-import Related to 'media import' command command:media-prune Related to 'media prune' command command:media-regenerate Related to 'media regenerate' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants