Skip to content

Exclude the wp-compat false positives from the PHPStan config - #12

Merged
swissspidy merged 1 commit into
mainfrom
fix/phpstan-wp-compat
Aug 26, 2026
Merged

swissspidy merged 1 commit into
mainfrom
fix/phpstan-wp-compat

Conversation

@swissspidy

Copy link
Copy Markdown
Member

The johnbillion/wp-compat PHPStan extension that now ships with wp-cli-tests reported 37 errors. It checks every WordPress symbol against the WordPress 4.9 baseline that wp-cli-tests configures, and only recognizes function_exists() and method_exists() guards.

All 37 are false positives, and for the simplest possible reason: every wp ability command is registered with a before_invoke that aborts below WordPress 6.9, and every flagged symbol is part of the Abilities API introduced in exactly that version. wp-compat does not look at before_invoke, so it reports the lot.

Count Symbols Version
6 wp_get_abilities(), wp_get_ability(), wp_has_ability(), wp_get_ability_categories(), wp_get_ability_category(), wp_has_ability_category() 6.9.0
24 WP_Ability:: — check_permissions, execute, get_category, get_description, get_input_schema, get_label, get_meta, get_meta_item, get_name, get_output_schema, normalize_input, validate_input 6.9.0
7 WP_Ability_Category:: — get_description, get_label, get_meta, get_slug 6.9.0

Ignored by error identifier and message, naming both the symbols and the version. Matching the version is the part that matters: scoping by class name alone would still have swallowed a hypothetical WP_Ability method added in a later release, whereas now anything introduced after 6.9 keeps being reported.

No source changes: nothing here is an actual compatibility problem.

An observation, not a change

Three of the pre-existing ignoreErrors patterns no longer match anything:

  • #Call to an undefined method WP_Ability::#
  • #Call to an undefined method WP_Ability_Category::#
  • #Cannot access offset string on mixed#

The first two are explained by the same dependency bump that motivates this PR — php-stubs/wordpress-stubs now carries the Abilities API, so the comment above them ("not yet in stubs") is out of date and the patterns are dead. They are silent because of reportUnmatched: false.

I have deliberately left them alone: that flag looks like intentional tolerance for resolving against an older stubs release, and removing the entries would give that up. Flagging it so you can decide.

Verification

Run locally against the same dependency versions CI resolves (johnbillion/wp-compat 2.0.0, php-stubs/wordpress-stubs v6.9.4, wp-cli/wp-cli-tests v5.2.3):

  • composer phpstan — [OK] No errors, with no unmatched ignore entries
  • As a control on the scoping, temporarily rewriting the entries to expect 7.0.0 instead of 6.9.0 makes all 37 errors resurface, confirming the version match is load-bearing rather than decorative

GitHub Actions was failing to allocate runners across the org while this was written, so CI may need a re-run once that clears.


Generated by Claude Code

The johnbillion/wp-compat extension that comes with wp-cli-tests checks every
WordPress symbol against the WordPress 4.9 baseline that wp-cli-tests
configures, and only recognizes function_exists() and method_exists() guards.
It cannot see the `before_invoke` check in ability-command.php that aborts every
`wp ability` command below WordPress 6.9, so all 37 errors it reports are false
positives.

Ignore them by error identifier and message, naming both the Abilities API
symbols and that version, so a call to anything introduced after WordPress 6.9
keeps being reported rather than swallowed by a file-wide ignore.

Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
Copilot AI lite review requested due to automatic review settings August 26, 2026 06:21
@swissspidy
swissspidy requested a review from a team as a code owner August 26, 2026 06:22

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 Aug 26, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 55 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 244c446b-99db-443a-a788-417f3f6fe2a6

📥 Commits

Reviewing files that changed from the base of the PR and between 7ce09c6 and 2e03189.

📒 Files selected for processing (1)
  • phpstan.neon.dist
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/phpstan-wp-compat

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 command:ability Related to 'ability' command command:ability-category Related to 'ability category' command command:ability-list Related to 'ability list' command command:ability-get Related to 'ability get' command command:ability-run Related to 'ability run' command command:ability-exists Related to 'ability exists' command command:ability-can-run Related to 'ability can-run' command command:ability-validate Related to 'ability validate' command command:ability-category-list Related to 'ability category list' command command:ability-category-get Related to 'ability category get' command command:ability-category-exists Related to 'ability category exists' command scope:testing Related to testing labels Aug 26, 2026
@codecov

codecov Bot commented Aug 26, 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 added this to the 1.0.3 milestone Aug 26, 2026
@swissspidy
swissspidy merged commit 3e44cdb into main Aug 26, 2026
57 checks passed
@swissspidy
swissspidy deleted the fix/phpstan-wp-compat branch August 26, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:ability Related to 'ability' command command:ability-can-run Related to 'ability can-run' command command:ability-category Related to 'ability category' command command:ability-category-exists Related to 'ability category exists' command command:ability-category-get Related to 'ability category get' command command:ability-category-list Related to 'ability category list' command command:ability-exists Related to 'ability exists' command command:ability-get Related to 'ability get' command command:ability-list Related to 'ability list' command command:ability-run Related to 'ability run' command command:ability-validate Related to 'ability validate' command scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants