Skip to content

PHPStan: Add dynamic return type extension for WP_CLI::get_config() - #346

Merged
swissspidy merged 3 commits into
mainfrom
add/phpstan-get-config
Jul 30, 2026
Merged

PHPStan: Add dynamic return type extension for WP_CLI::get_config()#346
swissspidy merged 3 commits into
mainfrom
add/phpstan-get-config

Conversation

@swissspidy

@swissspidy swissspidy commented Jul 30, 2026

Copy link
Copy Markdown
Member

Follow-up to #344 and #345

Summary by CodeRabbit

  • New Features

    • Added improved static analysis for 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

    • Expanded PHPStan fixture coverage to assert enhanced type precision for WP_CLI::get_config() calls, including get_config(null) and key-specific expectations (e.g., updated prompt/debug value types), plus cases for invalid keys.

@swissspidy swissspidy added this to the 5.2.0 milestone Jul 30, 2026
@swissspidy
swissspidy requested a review from a team as a code owner July 30, 2026 13:54
@swissspidy swissspidy added the scope:testing Related to testing label Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 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: b6f104bb-2203-4938-8501-54b9da2e2598

📥 Commits

Reviewing files that changed from the base of the PR and between 912f3aa and 626cd2b.

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

📝 Walkthrough

Walkthrough

Changes

WP-CLI config return types

Layer / File(s) Summary
Implement and register get_config inference
src/PHPStan/WPCliGetConfigDynamicReturnTypeExtension.php, extension.neon
Adds argument-sensitive return type inference for WP_CLI::get_config and registers the extension with PHPStan.
Validate inferred config types
tests/data/get_config.php, tests/tests/PHPStan/TestDynamicReturnTypeExtension.php
Adds assertions for global, key-specific, nullable, fallback, and invalid-key return types, and loads the fixture in the test provider.

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
Loading

Suggested reviewers: schlessera, brianhenryie, ernilambar

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a PHPStan dynamic return type extension for WP_CLI::get_config().
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 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add/phpstan-get-config

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 bootstrapFiles, bootstrapFile, or includes directives.


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.

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 71 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...PStan/WPCliGetConfigDynamicReturnTypeExtension.php 0.00% 71 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
tests/data/get_config.php (1)

17-27: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7eaba17 and 912f3aa.

📒 Files selected for processing (4)
  • extension.neon
  • src/PHPStan/WPCliGetConfigDynamicReturnTypeExtension.php
  • tests/data/get_config.php
  • tests/tests/PHPStan/TestDynamicReturnTypeExtension.php

Comment thread src/PHPStan/WPCliGetConfigDynamicReturnTypeExtension.php
Comment thread src/PHPStan/WPCliGetConfigDynamicReturnTypeExtension.php Outdated
Comment thread tests/data/get_config.php Outdated
@swissspidy

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@swissspidy
swissspidy merged commit f405348 into main Jul 30, 2026
79 of 80 checks passed
@swissspidy
swissspidy deleted the add/phpstan-get-config branch July 30, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant