szepeviktor/phpstan-wordpress
PHPStan extension that enables static analysis of WordPress plugins and themes: loads WordPress stubs, adds dynamic return types, defines core constants, and validates apply_filters/do_action docblocks. Requires PHPStan 2.0+ and PHP 7.4+.
apply_filters(), WP_Error narrowing, dynamic constants). This package collapses that into a dev dependency — the decision becomes "do we enforce static analysis at all?" rather than "can we afford to build WordPress-aware analysis?"get_sites(), term_exists(), wp_parse_url(), has_filter(), is_wp_error(), and hook callback signatures give teams the confidence to restructure legacy plugin code — a prerequisite for any "clean up the monolith plugin" roadmap item.apply_filters() docblock validation turns informal, undocumented hook contracts into machine-checked ones. This supports decisions about extensibility standards and public API stability for plugins that ship hooks to third parties.php-stubs/woocommerce-stubs for e-commerce plugin and theme estates.Adopt when:
extension.neon or phpstan/extension-installer).Look elsewhere or defer when:
Mitigations to require before adoption: pin an exact version, commit the lockfile, record the fallback (php-stubs/wordpress-stubs plus a hand-rolled extension.neon), and have one engineer able to fork it.
For executives: We can add automated correctness checking to our WordPress code for effectively zero license cost — it's MIT-licensed, installs as a dev dependency, and requires no configuration. It catches type errors, bad hook contracts, and upgrade incompatibilities at code-review time rather than in production. The decision is approval of a CI policy change, not a procurement. Principal caveat: it is maintained by a single volunteer who has publicly signaled intent to step back, so we should pin the version, own the fallback, and not treat it as a long-term vendor commitment.
For engineering leadership: This is the standard way to make PHPStan understand WordPress — core stubs, dynamic return types for functions the stubs miss, core constants, and apply_filters()/do_action() docblock validation. No setup beyond including extension.neon. It also enforces better habits: precise PHPDoc, OOP file structure, avoiding eval/extract/compact and type juggling, and preferring core functions over constants. Plan for PHPStan 2.0+ as a prerequisite.
For engineering teams: One composer require --dev, one include, then vendor/bin/phpstan analyze. Start at level 5, baseline existing errors, and block on new ones. Keep the first @param in filter docblocks accurate — the extension treats it as the return type. Use the published examples and the WooCommerce stubs guide for shops. Known rough edge: WordPress's conditional function/class definitions require a sed rename on stubs when functions are already defined; budget a small amount of setup friction for unusual codebases.
Ask: Approve a one-sprint pilot on one representative plugin — measure error count at level 5, fix rate, and CI runtime — with a go/no-go on wider rollout.
How can I help you explore Laravel packages today?