skukunin / phpstan-rules
Custom PHPStan rules for static analysis
v1.0.0
2025-06-01 12:03 UTC
Requires (Dev)
- phpstan/phpdoc-parser: ^2.1
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^12.1
- symfony/dependency-injection: ^7.3
- symfony/framework-bundle: ^7.3
README
This library provides a collection of custom PHPStan rules to help you enforce best practices in your PHP projects. It includes rules that will catch common anti-patterns and misuses, such as using deprecated methods, misusing container methods, and error silencing practices.
How to Use
- Installation: Install this library via Composer:
composer require skukunin/phpstan-rules --dev
- Configuration: Register the custom rules in your PHPStan configuration file (e.g.,
phpstan.neonorextension.neon).
You can add all the rules in your PHPStan configuration file:
includes: - phpstan-baseline.neon - vendor/skukunin/phpstan-rules/extension.neon parameters: level: 6 ...
or add only needed rules:
rules: - SKukunin\PHPStanRules\Rules\NoControllerGetParameterRule
- Running PHPStan: Run PHPStan on your project to report any detected issues:
vendor/bin/phpstan analyse src tests
Use Cases
- Symfony Projects: This library is designed with Symfony projects in mind. It provides rules to enforce best practices such as avoiding the use of
getParameterin controllers, encouraging better dependency injection practices. - Legacy Codebases: Gradually refactor and improve legacy code by integrating these rules to catch common pitfalls.
- CI/CD Integration: Ensure code quality across your projects by integrating these custom PHPStan rules into your automated build pipelines.
Existing Rules
NoContainerGetRule: Prevents misuse of container get methods.NoControllerGetParameterRule: Flags the usage ofgetParameterwithin controllers.NoErrorSilencingRule: Disallows use of PHP's error suppression operator (@).
Contributing
Contributions are welcome! If you encounter issues or have ideas for enhancements, please open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License.