szepeviktor/phpstan-wordpress
PHPStan rules and stubs tailored for WordPress projects. Adds accurate type information for core functions, hooks, and globals to catch bugs earlier and improve static analysis in plugins and themes. Easy to integrate into existing PHPStan setups.
phpstan/extension-installer, this package bridges WordPress-specific logic (e.g., add_action, wp_query, get_template_part) into Laravel’s static analysis pipeline. Useful for:
phpstan.neon), minimizing architectural disruption.phpstan/extension-installer (v1.1.0+) can auto-install this package via composer require --dev szepeviktor/phpstan-wordpress.wp-load.php, WP_ globals). In pure Laravel projects, false positives may arise unless:
wp-load.php in a Laravel service provider).brain/monkey or custom PHPStan stubs).$wpdb, $post, etc., may clash with Laravel’s dependency injection. Mitigate via:
WP\ prefix).add_action called at runtime). Requires manual @method annotations or custom rules.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| False Positives | High | Whitelist known WordPress patterns in phpstan.neon. |
| WordPress Dependency | Critical | Isolate WordPress logic to dedicated modules. |
| Performance Overhead | Medium | Exclude WordPress-specific files from analysis via includes in phpstan.neon. |
| Hook Resolution | High | Supplement with custom PHPStan rules or @var annotations. |
| Laravel-WP Hybrid Issues | High | Use feature flags to toggle WordPress logic. |
rector, pestphp, or custom scripts)?wp-load.php in a Laravel service provider).wp_, add_action, get_posts).phpstan/extension-installer (if not present):
composer require --dev phpstan/extension-installer
composer.json:
"extra": {
"phpstan": {
"extension-classes": ["szepeviktor\\phpstan_wordpress\\extension"]
}
}
phpstan.neon:
includes:
- vendor/szepeviktor/phpstan-wordpress/extension.neon
--level=5 (strict) for new code; --level=3 for legacy.phpstan.neon:
rules:
szepeviktor\WordPress\Rules\DisallowDirectQuery::class: false
@var annotations for dynamic hooks:
/** @var array<string, callable> $wp_filter */
App facade by namespacing WordPress globals.phpstan.neon to exclude non-WordPress files.@var annotations for dynamic logic.- name: PHPStan
run: vendor/bin/phpstan analyse --level=5
szepeviktor/phpstan-wordpress for breaking changes (MIT license allows forks if needed).add_action with runtime callbacks not analyzed").add_action called in a plugin).WP_Query).--generate-baseline to suppress known issues temporarily.How can I help you explore Laravel packages today?