talira

WordPress Extensions for PHPStan

Static analysis for WordPress plugins and themes with PHPStan

open sourceMITfree

WordPress Extensions for PHPStan lets PHPStan analyse WordPress plugins and themes. It loads the php-stubs/wordpress-stubs package, adds dynamic return types for WordPress functions the stubs don't cover, defines some WordPress core constants, and reads the docblocks WordPress puts before apply_filters() and do_action() calls, treating the first @param as the type. It's installed with Composer as szepeviktor/phpstan-wordpress.

Problems it solves

  • run PHPStan on my WordPress plugin without errors about unknown WordPress functions
  • catch type errors in my WordPress theme's PHP before it ships
  • get PHPStan to understand the types passed through WordPress filters

Features

  • loads php-stubs/wordpress-stubs
  • dynamic return types for WordPress functions the stubs don't cover
  • defines some WordPress core constants
  • reads apply_filters() and do_action() docblocks, treating the first @param as the type

Alternatives

The same job

These do what WordPress Extensions for PHPStan does.

  1. PHPStan PHP static analysis that finds bugs without running your code
  2. Phan A static analyzer for PHP that minimizes false positives
  3. Larastan Adds code analysis to Laravel, improving developer productivity and code quality
  4. Psalm Free and open source static analysis tool for finding errors in PHP code

Compare WordPress Extensions for PHPStan with the top 3