Skip to content

Fix WPCliRuncommandDynamicReturnTypeExtension when passing invalid options#339

Merged
schlessera merged 1 commit into
mainfrom
fix/runcommand-hardening
Jul 23, 2026
Merged

Fix WPCliRuncommandDynamicReturnTypeExtension when passing invalid options#339
schlessera merged 1 commit into
mainfrom
fix/runcommand-hardening

Conversation

@swissspidy

@swissspidy swissspidy commented Jul 23, 2026

Copy link
Copy Markdown
Member

Any call like WP_CLI::runcommand('plugin list') (omitting options or omitting 'return') was wrongly typed by PHPStan as string instead of null.

As noticed in wp-cli/wp-cli#6345

Summary by CodeRabbit

  • Bug Fixes
    • Improved type inference for WP_CLI::runcommand() when no return option is specified.
    • Calls that execute commands without returning output are now correctly inferred as returning null.
    • Added coverage for default behavior and calls with exit_error disabled.

@swissspidy swissspidy added this to the 5.1.12 milestone Jul 23, 2026
@swissspidy
swissspidy requested a review from a team as a code owner July 23, 2026 07:44
@github-actions github-actions Bot added bug Something isn't working scope:testing labels Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 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: eb8abd10-0cd1-4623-9c16-666a0497a215

📥 Commits

Reviewing files that changed from the base of the PR and between 0c0b800 and 85501aa.

📒 Files selected for processing (2)
  • src/PHPStan/WPCliRuncommandDynamicReturnTypeExtension.php
  • tests/data/runcommand.php

📝 Walkthrough

Walkthrough

The dynamic return type extension now defaults an unspecified return option to false. Test cases verify that WP_CLI::runcommand() returns null for default options and when exit_error is explicitly disabled.

Changes

Runcommand return inference

Layer / File(s) Summary
Default return inference and validation
src/PHPStan/WPCliRuncommandDynamicReturnTypeExtension.php, tests/data/runcommand.php
The inferred default return option is changed to false, with assertions covering default plugin list calls and calls using exit_error => false that return null.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions invalid options, but the change actually fixes the default PHPStan return type when no return option is provided. Rename it to reflect the typing fix, e.g. "Fix WP_CLI::runcommand() return type when no return option is set".
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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/runcommand-hardening

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.2.5)

PHPStan was skipped because the config uses disallowed bootstrapFiles, bootstrapFile, or includes directives.


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

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...Stan/WPCliRuncommandDynamicReturnTypeExtension.php 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@schlessera
schlessera merged commit 0af4e54 into main Jul 23, 2026
84 checks passed
@schlessera
schlessera deleted the fix/runcommand-hardening branch July 23, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working scope:testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants