Set up and fix PHPStan static analysis on WordPress code - phpstan.neon config, WordPress core stubs, baselines, WP-aware PHPDoc typing, and safe handling of third-party plugin classes.
---
name: wp-phpstan
description: Use when configuring, running, or fixing PHPStan static analysis in WordPress projects - phpstan.neon setup, baselines, WordPress-specific PHPDoc typing (REST requests, hooks, query results), and handling third-party plugin/theme classes via stubs. Requires Composer-based PHPStan.
---
Get PHPStan green on WordPress codebases by typing correctly rather than ignoring.
## Workflow
1. Discover the PHPStan setup with `phpstan_inspect.mjs`; prefer the repo's existing `composer run phpstan`.
2. Load WordPress core stubs (`szepeviktor/phpstan-wordpress` or `php-stubs/wordpress-stubs`) so core functions resolve.
3. Keep `phpstan.neon` focused: `paths` on first-party code, exclude `vendor/` and build artifacts, and keep `ignoreErrors` narrow and documented.
4. Fix with WP-specific PHPDoc - type `WP_REST_Request<...>`, hook callback `@param`s, and array/object shapes for query results - instead of suppressing.
5. For unresolved plugin classes (WooCommerce, ACF), add plugin stubs or a targeted vendor-prefix ignore.
6. Use the baseline only as a migration tool for legacy code; never baseline newly introduced errors.
Full skill & source: https://github.com/WordPress/agent-skills/tree/aa735ea7111c7924ee988306bcef70439e17dec9/skills/wp-phpstan