Skip to the guide
All guides

PHPStan

Check that PHPStan really analyzes your WordPress plugin or theme and that its CI step fails on type errors. The skill also helps you fix real diagnostics without hiding them.

app WordPress DevKit 2.0.3checked reading 5 minutes

On this page

When to use it

Use this skill to set up, debug or review PHPStan for a WordPress plugin or theme. It covers NEON config and levels, the szepeviktor/phpstan-wordpress extension and the WordPress and WooCommerce stubs, undefined symbols, WP_Error and hook typing, baselines, ignores, and CI gates that must fail on type errors. NEON is the config file format PHPStan uses, and stubs are type declarations for code PHPStan does not load.

Other skills for nearby topics

  • PHPCS and WordPress Coding Standards, PHPUnit and browser tests: wp-devkit-test-strategy.
  • CI workflow design and release gates: wp-devkit-ci-cd-and-release-engineering.
  • Plugin architecture changes: wp-devkit-plugin-development.
  • Security conclusions: wp-devkit-security-review. Types do not model permissions.

Run a review in Claude

With the plugin loaded, start a read-only review of one bounded target:

Text
/wp-devkit:phpstan-review <target-path>

The short form /wp-devkit:phpstan asks for a quick scan.

Run a review in Codex, ChatGPT or Antigravity

Name the installed skill and keep the request small. Replace the target with your files or the journey you care about.

Text
$wp-devkit-phpstan-review
Review the target without editing files.
Read the project instructions and the skill's engineering contract first.
Separate confirmed findings from candidates and state the evidence and checks you could not run.

The engineering contract is the set of rules every DevKit skill follows, such as how severity is graded and what counts as evidence.

Reference files

The agent loads only the file that matches your task:

  • config-and-discovery.md applies to configuration and undefined-symbol problems. It covers levels, config keys, precedence, how PHPStan discovers symbols, the extension and stubs, the PHP version and the cache.
  • wordpress-type-patterns.md helps when you triage real diagnostics. It shows how to type WordPress return unions, hooks, options, meta, requests, $wpdb and WooCommerce objects without hiding bugs.
  • baseline-ignores-and-ci.md applies to suppressions and gates. It covers baselines, ignore forms, identifiers, CI wiring, adoption strategy and PHPStan upgrades.
  • phpstan-review-workbook.md holds symptom triage, worked decisions, look-alikes that are not defects, and verification steps.

How a review runs

  1. The agent resolves the configuration the real command uses. The order is the -c or --configuration option, then phpstan.neon, phpstan.neon.dist and phpstan.dist.neon in the working directory. Paths given on the command line replace paths. Every includes: entry is followed.
  2. It compares the analyzed paths and excludePaths with the inventory of first-party code: plugin root files, src/, inc/, templates, uninstall.php, mu-plugin loaders and CLI classes. Excluded production files that fail analysis are the first thing to look for.
  3. It separates analysis from discovery. PHPStan analyzes paths. scanFiles and scanDirectories only make symbols known. PHP executes bootstrapFiles. The agent confirms that the WordPress extension and stubs load once, either through the extension installer or one explicit include, and that WooCommerce and WP-CLI stubs exist when their symbols are used.
  4. It checks the level and the strictness settings. The level should be a number from 0 to 10 rather than max, with a reason for the choice. treatPhpDocTypesAsCertain, phpVersion and tmpDir should be set on purpose.
  5. It sorts diagnostics by class: undefined symbol (a discovery problem), real type error, missing PHPDoc, and WordPress dynamic types such as WP_Error|T, hooks and mixed options. The agent corrects the real contract. It does not add a cast or an ignore to silence a true defect.
  6. It reviews suppressions and the baseline: identifiers, paths, counts, reportUnmatchedIgnoredErrors, comments, and whether new errors stay visible.
  7. It verifies the gate. CI must run the same command, fail the job on a nonzero exit, avoid continue-on-error, never regenerate the baseline, and fail when a deliberate type error is added. The workbook holds the severity rules, the finding template, false positives and acceptance checks.

What you get back

The report leads with the verdict and the reviewed scope. It records the PHPStan, extension and stubs versions, the PHP version, the level, the config file, analyzed and excluded paths, the baseline policy, and the command with its exit status.

Each finding lists its severity, file:line (config or code), what is uncovered or wrong, the impact (which class of defect can now slip through), confidence, a minimal fix, and a positive and negative regression check. Resolved findings are kept apart from excluded or unexecuted code. The report also says whether each change corrects the type contract or the runtime behavior.

A green run proves only that the analyzed code satisfies the rules at that level. It says nothing about code outside paths, runtime behavior or security.

Note

Reviews are read-only. A clean review covers the code that was inspected and is not a certification. Ask for implementation as a separate, bounded task with a regression check.

Where to go next

Use review to fix to turn findings into a bounded change. Use Doctor and reports for environment checks and evidence tooling.