Use when configuring, running, or fixing PHPStan static analysis in WordPress projects (plugins/themes/sites): phpstan.neon setup, baselines, WordPress-specific typing, and handling third-party plugin classes.
Add this skill
npx mdskills install WordPress/wp-phpstanComprehensive PHPStan guidance for WordPress with clear procedures, diagnostic tooling, and third-party handling
1---2name: wp-phpstan3description: "Use when configuring, running, or fixing PHPStan static analysis in WordPress projects (plugins/themes/sites): phpstan.neon setup, baselines, WordPress-specific typing, and handling third-party plugin classes."4compatibility: "Targets WordPress 6.9+ (PHP 7.2.24+). Requires Composer-based PHPStan."5---67# WP PHPStan89## When to use1011Use this skill when working on PHPStan in a WordPress codebase, for example:1213- setting up or updating `phpstan.neon` / `phpstan.neon.dist`14- generating or updating `phpstan-baseline.neon`15- fixing PHPStan errors via WordPress-friendly PHPDoc (REST requests, hooks, query results)16- handling third-party plugin/theme classes safely (stubs/autoload/targeted ignores)1718## Inputs required1920- `wp-project-triage` output (run first if you haven't)21- Whether adding/updating Composer dev dependencies is allowed (stubs).22- Whether changing the baseline is allowed for this task.2324## Procedure2526### 0) Discover PHPStan entrypoints (deterministic)271. Inspect PHPStan setup (config, baseline, scripts):28 - `node skills/wp-phpstan/scripts/phpstan_inspect.mjs`2930Prefer the repo’s existing `composer` script (e.g. `composer run phpstan`) when present.3132### 1) Ensure WordPress core stubs are loaded3334`szepeviktor/phpstan-wordpress` or `php-stubs/wordpress-stubs` are effectively required for most WordPress plugin/theme repos. Without it, expect a high volume of errors about unknown WordPress core functions.3536- Confirm the package is installed (see `composer.dependencies` in the inspect report).37- Ensure the PHPStan config references the stubs (see `references/third-party-classes.md`).3839### 2) Ensure a sane `phpstan.neon` for WordPress projects4041- Keep `paths` focused on first-party code (plugin/theme directories).42- Exclude generated and vendored code (`vendor/`, `node_modules/`, build artifacts, tests unless explicitly analyzed).43- Keep `ignoreErrors` entries narrow and documented.4445See:46- `references/configuration.md`4748### 3) Fix errors with WordPress-specific typing (preferred)4950Prefer correcting types over ignoring errors. Common WP patterns that need help:5152- REST endpoints: type request parameters using `WP_REST_Request<...>`53- Hook callbacks: add accurate `@param` types for callback args54- Database results and iterables: use array shapes or object shapes for query results55- Action Scheduler: type `$args` array shapes for job callbacks5657See:58- `references/wordpress-annotations.md`5960### 4) Handle third-party plugin/theme classes (only when needed)6162When integrating with plugins/themes not present in the analysis environment:6364- First, confirm the dependency is real (installed/required).65- Prefer plugin-specific stubs already used in the repo (common examples: `php-stubs/woocommerce-stubs`, `php-stubs/acf-pro-stubs`).66- If PHPStan still cannot resolve classes, add targeted `ignoreErrors` patterns for the specific vendor prefix.6768See:69- `references/third-party-classes.md`7071### 5) Baseline management (use as a migration tool, not a trash bin)7273- Generate a baseline once for legacy code, then reduce it over time.74- Do not “baseline” newly introduced errors.7576See:77- `references/configuration.md`7879## Verification8081- Run PHPStan using the discovered command (`composer run ...` or `vendor/bin/phpstan analyse`).82- Confirm the baseline file (if used) is included and didn’t grow unexpectedly.83- Re-run after changing `ignoreErrors` to ensure patterns are not masking unrelated issues.8485## Failure modes / debugging8687- “Class not found”:88 - confirm autoloading/stubs, or add a narrow ignore pattern89- Huge error counts after enabling PHPStan:90 - reduce `paths`, add `excludePaths`, start at a lower level, then ratchet up91- Inconsistent types around hooks / REST params:92 - add explicit PHPDoc (see references) rather than runtime guards9394## Escalation9596- If a type depends on a third-party plugin API you can’t confirm, ask for the dependency version or source before inventing types.97- If fixing requires adding new Composer dependencies (stubs/extensions), confirm it with the user first.98
Full transparency — inspect the skill content before installing.