PHPStan: Add rule for WP_CLI::add_hook() usage - #345
Conversation
|
Warning Review limit reached
Next review available in: 54 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds and registers a PHPStan rule that validates ChangesHook callback validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant PHPStan
participant WPCliAddHookCallbackRule
participant WP_CLI
PHPStan->>WPCliAddHookCallbackRule: process StaticCall node
WPCliAddHookCallbackRule->>WP_CLI: inspect add_hook callback and hook name
WPCliAddHookCallbackRule-->>PHPStan: return callable or argument-count error
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
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: 1
🧹 Nitpick comments (2)
tests/data/add_hook_rule.php (1)
17-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove redundant callback-body comments.
The surrounding scenario labels already describe each case; these
// validand// invalidcomments add no test intent.As per coding guidelines, “Write only high-value inline comments and avoid addressing users through code comments.”
Also applies to: 25-25, 33-33, 41-41, 49-49
🤖 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/add_hook_rule.php` at line 17, Remove the redundant `// valid` and `// invalid` comments from the callback bodies in the affected test cases, including the locations referenced by the review. Keep the surrounding scenario labels and test behavior unchanged.Source: Coding guidelines
tests/tests/PHPStan/TestWPCliAddHookCallbackRule.php (1)
14-14: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftAlign the PHPStan rule test with the required
WP_CLI\Tests\TestCasecontract.
TestWPCliAddHookCallbackRuledirectly extendsPHPStan\Testing\RuleTestCase; PHPStan tests cannot inherit both PHPStan’s rule base and the required WP-CLI test base, so either document this as an intentionalphpstan-extensionexception or refit the test through an approved bridge/base class.🤖 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/tests/PHPStan/TestWPCliAddHookCallbackRule.php` at line 14, Update TestWPCliAddHookCallbackRule to satisfy the required WP_CLI\Tests\TestCase contract: use the approved bridge/base class if one exists, otherwise document this direct RuleTestCase inheritance as an intentional phpstan-extension exception. Preserve the test’s PHPStan rule-testing behavior.Source: Coding guidelines
🤖 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/WPCliAddHookCallbackRule.php`:
- Around line 69-76: Update both RuleErrorBuilder::message() sites in
WPCliAddHookCallbackRule::processNode() to assign stable identifier() values
before build(): one identifier for invalid callbacks at lines 69-76 and a
distinct identifier for insufficient required parameters at lines 107-118.
---
Nitpick comments:
In `@tests/data/add_hook_rule.php`:
- Line 17: Remove the redundant `// valid` and `// invalid` comments from the
callback bodies in the affected test cases, including the locations referenced
by the review. Keep the surrounding scenario labels and test behavior unchanged.
In `@tests/tests/PHPStan/TestWPCliAddHookCallbackRule.php`:
- Line 14: Update TestWPCliAddHookCallbackRule to satisfy the required
WP_CLI\Tests\TestCase contract: use the approved bridge/base class if one
exists, otherwise document this direct RuleTestCase inheritance as an
intentional phpstan-extension exception. Preserve the test’s PHPStan
rule-testing behavior.
🪄 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: 8507a998-a180-4c45-af4a-a0b09e122a87
📒 Files selected for processing (4)
extension.neonsrc/PHPStan/WPCliAddHookCallbackRule.phptests/data/add_hook_rule.phptests/tests/PHPStan/TestWPCliAddHookCallbackRule.php
Complements #344
Summary by CodeRabbit
New Features
WP_CLI::add_hook()callbacks.Tests