Uh oh!
There was an error while loading. Please reload this page.
PHPStan: Add dynamic return type extension for WP_CLI::get_config() - #346
Conversation
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughChangesWP-CLI config return types
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant PHPStan
participant WPCliGetConfigDynamicReturnTypeExtension
participant ConfigTypeMap
PHPStan->>WPCliGetConfigDynamicReturnTypeExtension: Analyze static get_config call
WPCliGetConfigDynamicReturnTypeExtension->>ConfigTypeMap: Resolve configuration key types
ConfigTypeMap-->>WPCliGetConfigDynamicReturnTypeExtension: Return mapped or fallback type
WPCliGetConfigDynamicReturnTypeExtension-->>PHPStan: Return inferred Type
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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.6)PHPStan was skipped because the config uses disallowed 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. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
tests/data/get_config.php (1)
17-27: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winCover nullable and non-constant key paths.
The implementation has dedicated branches for nullable and unknown key types, but this fixture only tests literal keys. Add assertions for
get_config( null ), a nullable key, and a non-constant string key.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/data/get_config.php` around lines 17 - 27, Extend the get_config type assertions in the test fixture to cover the dedicated nullable and unknown-key branches: add assertions for get_config(null), a nullable key value, and a non-constant string key, using the expected return types for each path while preserving the existing literal-key assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/PHPStan/WPCliGetConfigDynamicReturnTypeExtension.php`:
- Around line 97-108: Align the `=>` arrows in the array entries within
`WPCliGetConfigDynamicReturnTypeExtension.php`, including the shown
configuration keys, to satisfy the `WP_CLI_CS` MultipleStatementAlignment rule.
Use PHPCBF or apply consistent spacing across all affected entries, preserving
their keys and values.
- Around line 92-94: Update the fixture handling for the debug and prompt
configuration values to reuse the existing $stringOrTrue and $stringOrFalse
helpers, preserving their literal boolean types instead of widening them to
generic bool|string. Adjust the related test assertion to expect these literal
types, while leaving $trueOrStringList unchanged.
In `@tests/data/get_config.php`:
- Line 15: Update the array-shape type passed to assertType in
WP_CLI::get_config() so every hyphenated key—ssh-args, skip-plugins,
skip-themes, skip-packages, assume-https, and allow-root—is enclosed in quotes;
leave the remaining keys and assertions unchanged.
---
Nitpick comments:
In `@tests/data/get_config.php`:
- Around line 17-27: Extend the get_config type assertions in the test fixture
to cover the dedicated nullable and unknown-key branches: add assertions for
get_config(null), a nullable key value, and a non-constant string key, using the
expected return types for each path while preserving the existing literal-key
assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 5b8ff758-4c5e-41ef-b02f-462683a4d1e6
📒 Files selected for processing (4)
extension.neonsrc/PHPStan/WPCliGetConfigDynamicReturnTypeExtension.phptests/data/get_config.phptests/tests/PHPStan/TestDynamicReturnTypeExtension.php
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
swissspidy
commented
Jul 30, 2026
@coderabbitai review |
✅ Action performedReview finished.
|
Follow-up to #344 and #345
Summary by CodeRabbit
New Features
WP_CLI::get_config(), inferring more accurate return types based on the configuration key requested (including global results, known keys, nullable keys, and unknown/non-constant keys).Tests
WP_CLI::get_config()calls, includingget_config(null)and key-specific expectations (e.g., updatedprompt/debugvalue types), plus cases for invalid keys.