Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Phpstan Wordpress

Phpstan Wordpress Laravel Package

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.

View on GitHub
Deep Wiki
Context7

WordPress extensions for PHPStan

Frequently asked questions about Phpstan Wordpress
Can I use this package in a Laravel project that interacts with WordPress via REST API?
Yes, but with caveats. The package assumes WordPress globals and functions are available, so you’ll need to mock or stub WordPress-specific code in your Laravel tests. For REST API integrations, focus on validating responses rather than core WordPress functions, as those won’t be statically analyzable without a full WordPress environment.
How do I install this in a Laravel project using phpstan/extension-installer?
Run `composer require --dev szepeviktor/phpstan-wordpress` and ensure your `phpstan.neon` includes the extension under `[phpstan.extension]`. If using `phpstan/extension-installer`, it will auto-detect and install this package alongside other PHPStan extensions. Verify compatibility with PHPStan 1.10+ in your `composer.json` constraints.
Will this break my existing PHPStan configuration for Laravel?
No, it’s designed to be non-invasive. The package extends PHPStan’s rules without modifying Laravel’s core setup. However, you may need to adjust `includes` or `exclude` paths in `phpstan.neon` to avoid false positives in non-WordPress parts of your Laravel app. Test incrementally by enabling the extension for specific directories first.
Does this package support WordPress plugins or only themes?
It supports both plugins and themes by providing type hints for core WordPress functions, hooks (`add_action`, `add_filter`), and globals like `$wpdb` or `$post`. For plugins, it’s especially useful for validating hook callbacks, action parameters, and dynamic function calls. Themes benefit from checks on template functions like `get_template_part()` or `wp_get_theme()`.
How do I handle false positives when WordPress isn’t fully loaded in Laravel?
False positives occur when PHPStan detects WordPress functions without a WordPress environment. Mitigate this by whitelisting known patterns in `phpstan.neon` (e.g., `excludePaths` for Laravel-only files) or using `@var` annotations to suppress checks in hybrid code. For CI/CD, treat WordPress-specific rules as advisory unless you’ve bootstrapped WordPress in your test environment.
Can I use this with Laravel’s built-in testing (Pest or PHPUnit)?
Yes, but you’ll need to mock WordPress globals or load `wp-load.php` in your test environment. For Pest/PHPUnit, use `brain/monkey` to patch WordPress functions or create custom PHPStan stubs. Avoid running PHPStan in pure Laravel test suites unless WordPress is explicitly required, as it may flag unrelated code with false positives.
What Laravel versions does this package support?
This package doesn’t enforce Laravel-specific rules, so it’s compatible with all Laravel versions (5.8+). However, integration depends on your project’s WordPress setup. For hybrid apps, ensure your Laravel service providers conditionally load WordPress (e.g., via `if (function_exists('wp_load'))`) to avoid runtime conflicts with the service container.
Are there alternatives for static analysis in Laravel-WordPress projects?
If you’re not using PHPStan, consider Psalm with its WordPress extension (`vimeo/psalm-plugin-wordpress`), though it has fewer Laravel integrations. For lightweight checks, use Laravel’s built-in tools (e.g., `php artisan make:test`) combined with WordPress’s `WP_CLI` for core validation. However, PHPStan + this package offers deeper static analysis for hybrid projects.
How do I configure this for a headless WordPress setup where Laravel consumes the REST API?
Focus on validating REST API responses in Laravel, not WordPress internals. Use PHPStan to type-hint your API client (e.g., Guzzle) and response models. For WordPress-specific checks, limit the extension to directories containing WordPress logic (e.g., a `wordpress/` module) and exclude the rest via `phpstan.neon`. Avoid analyzing `wp-load.php` or core WordPress files directly.
What’s the performance impact of running this in CI/CD for a large Laravel-WordPress codebase?
The package adds minimal overhead if configured properly. Exclude non-WordPress files from analysis in `phpstan.neon` and run it in parallel with other checks. For large codebases, cache PHPStan results using tools like `phpstan --generate-baseline` and integrate it as a pre-commit hook (e.g., via Laravel Pint or Git hooks) to fail fast on WordPress-specific issues.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor