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 Rules

Phpstan Rules Laravel Package

symplify/phpstan-rules

Extra PHPStan rules by Symplify to catch bugs, improve code quality, and enforce consistent conventions. Easy to install and configure, with a broad set of checks for Symfony/Laravel and modern PHP features to keep your codebase clean.

View on GitHub
Deep Wiki
Context7

Fun, powerful and practical PHPStan rules for Symfony, Doctrine, PHPUnit or plain PHP projects

Frequently asked questions about Phpstan Rules
Can I use symplify/phpstan-rules in a Laravel project without Symfony or Doctrine?
Yes, many rules are framework-agnostic and work for plain PHP or Laravel projects. Focus on the `naming-rules.neon`, `static-rules.neon`, and `code-complexity-rules.neon` sets first, as they apply broadly. Avoid Symfony-specific rules (e.g., `symfony-rules.neon`) unless you’re using Symfony components.
How do I install and configure symplify/phpstan-rules for Laravel?
Run `composer require --dev symplify/phpstan-rules phpstan/extension-installer`, then add includes to your `phpstan.neon` file. Start with minimal rules like `naming-rules.neon` and `static-rules.neon` to avoid overwhelming your team. Use `phpstan/extension-installer` to auto-load configurations.
Will symplify/phpstan-rules slow down my Laravel project’s CI pipeline?
Running 80+ rules can increase analysis time, especially for large codebases. Mitigate this by enabling rules incrementally (e.g., start with `naming-rules`) or running a subset in CI. Use PHPStan’s `--parallel` flag or exclude less critical rules to optimize performance.
Are there Laravel-specific rules missing, like checks for Facade usage or Blade templates?
Currently, the package focuses on Symfony/Doctrine/PHPUnit rules, but many are adaptable. For Laravel-specific needs, consider combining it with custom PHPStan rules or tools like `laravel-pint`. The package’s modular design allows you to extend or override rules for Laravel conventions.
How do I handle false positives, like Symfony rules conflicting with Laravel’s service container?
Disable conflicting rules in `phpstan.neon` or use the `MaximumIgnoredErrorCountRule` to limit ignored violations. For example, exclude `SingleRequiredMethodRule` if it conflicts with Laravel’s autowiring. Test locally before enforcing rules in CI to catch edge cases.
Can I enable symplify/phpstan-rules for PHP 8.3+ or Laravel 11+ features?
The package supports modern PHP features like attributes and enums, but some rules may need updates for newer Laravel versions. Monitor the repository for compatibility releases. Start with basic rules and gradually enable advanced ones as they’re updated for newer PHP/Laravel versions.
How do I enforce these rules in CI without breaking builds?
Start by treating violations as warnings (non-blocking) and gradually enforce them as blockers. Use `MaximumIgnoredErrorCountRule` to cap ignored errors and avoid rule fatigue. Run PHPStan locally first to identify and fix violations before pushing to CI.
What’s the best way to adopt symplify/phpstan-rules in a legacy Laravel codebase?
Enable rules incrementally, starting with low-impact sets like `naming-rules` or `static-rules`. Use whitelisting for legacy code and focus on critical violations first. Avoid enabling all rules at once, as this may overwhelm your team and cause unnecessary refactoring.
Are there alternatives to symplify/phpstan-rules for Laravel-specific static analysis?
For Laravel-specific checks, consider `phpstan/extension-installer` with custom rules or tools like `laravel-pint` for formatting. However, `symplify/phpstan-rules` offers broader coverage for Symfony/Doctrine/PHPUnit, which many Laravel projects use. Combine it with Laravel-focused tools for a comprehensive setup.
How do I configure symplify/phpstan-rules to improve Laravel’s service container type safety?
Enable the `laravelReturnType` parameter in `phpstan.neon` to resolve `$container->make(SomeService::class)` to `SomeService`. This requires `phpstan/extension-installer` and provides sharper type inference. Test thoroughly, as some Laravel-specific edge cases may need manual adjustments.
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony