Download the PHP package simtel/phpstan-rules without Composer
On this page you can find all versions of the php package simtel/phpstan-rules. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phpstan-rules
PHPStan Extended Rules
A collection of custom PHPStan rules that enforce coding standards and improve code quality in PHP projects. This extension provides additional static analysis rules focused on naming conventions, annotations, and PHPDoc consistency.
🎯 Features
This package includes three powerful rules that help maintain high code quality:
1. Command-Handler Relationship Rule
Rule: CommandClassShouldBeHelpCommandHandlerClass
Enforces that classes ending with "Command" must have a @see PHPDoc tag pointing to their corresponding CommandHandler class.
Example:
Exception: Classes with an __invoke method are exempt from this rule.
2. Event Listener Attribute Rule
Rule: EventListenerClassShouldBeIncludeAsListenerAttribute
Ensures that classes ending with "EventListener" are properly annotated with the #[AsEventListener] attribute.
Example:
3. Redundant PHPDoc Return Type Rule
Rule: NotShouldPhpdocReturnIfExistTypeHint
Prevents redundant or conflicting @return PHPDoc annotations when native return type hints are already declared.
Good:
Bad:
📦 Installation
System Requirements
- PHP: >8.3
- PHPStan: ^2.0
- PHPStan PHPDoc Parser: ^2.2
Install via Composer
Install the package as a development dependency:
⚙️ Configuration
Option 1: Include All Rules (Recommended)
Add the bundled configuration to your phpstan.neon or phpstan.dist.neon:
Option 2: Manual Rule Registration
For granular control, register specific rules:
Complete Configuration Example
🔧 Development
Setting Up Development Environment
-
Clone the repository:
- Install dependencies:
Development Commands
Running Tests
Code Style
Static Analysis
Project Structure
Creating New Rules
-
Implement the Rule Interface:
-
Create Test Cases:
- Add Fixture Files: Create test PHP files in
tests/Fixture/to validate rule behavior.
Testing Strategy
The project uses PHPUnit with PHPStan's RuleTestCase base class:
- Fixture Files: Real PHP code examples in
tests/Fixture/ - Data Files: Additional test scenarios in
tests/data/ - Unit Tests: Each rule has corresponding test class in
tests/Rules/
Contributing Guidelines
- Code Standards: Follow PSR-4 autoloading and use ECS for code style
- Testing: All rules must have comprehensive tests with both positive and negative cases
- Documentation: Update README.md and add inline documentation for new rules
- Performance: Ensure rules execute efficiently within PHPStan's analysis pipeline
🐛 Troubleshooting
Common Issues
"Rule Not Found" Errors
Cause: Incorrect namespace or class name in phpstan.neon.
Solution: Verify the fully qualified class names and check for typos.
Rules Not Being Applied
Cause: Configuration file not included or rules not registered.
Solution: Ensure vendor/simtel/phpstan-rules/rules.neon is included in your PHPStan configuration.
Performance Issues
Cause: Rules may be analyzing too many files or performing expensive operations.
Solution: Use excludePaths to limit analysis scope or optimize rule logic.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📞 Support
If you encounter any issues or have questions, please open an issue on GitHub.