skukunin/phpstan-rules

Custom PHPStan rules for static analysis

Maintainers

Package info

github.com/skukunin/phpstan-rules

pkg:composer/skukunin/phpstan-rules

Statistics

Installs: 34

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2025-06-01 12:03 UTC

This package is auto-updated.

Last update: 2026-03-28 15:25:56 UTC


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

  1. Installation: Install this library via Composer:
composer require skukunin/phpstan-rules --dev
  1. Configuration: Register the custom rules in your PHPStan configuration file (e.g., phpstan.neon or extension.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
  1. 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 getParameter in 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 of getParameter within 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.