Releases: Phauthentic/phpstan-rules
Releases · Phauthentic/phpstan-rules
1.2.1
Release Notes
🐛 Bug Fixes
Final Class Rule
- Fixed: Abstract classes are now properly ignored by default to prevent false positives
- Added: Configurable
ignoreAbstractClassesparameter (default:true) for users who want to enforce final declaration on abstract classes
Configuration
- class: Phauthentic\PHPStanRules\Architecture\ClassMustBeFinalRule arguments: patterns: ['/^App\\Service\\/'] ignoreAbstractClasses: true # Default behavior tags: - phpstan.rules.ruleBackward Compatible: All existing configurations continue to work without changes.
1.2.0: Improving the MethodMustReturnType to support unions (#7)
Release Notes
🎉 New Features
✨ Enhanced Method Must Return Type Rule
- New Feature: Added support for "void" as a type in addition to the legacy
void: trueapproach - New Feature: Added
oneOffunctionality for union types - allows specifying an array of types where one must match - New Feature: Added
allOffunctionality for union types - allows specifying an array of types where all must be present - New Feature: Added
anyOfas an alias foroneOffor better readability - New Feature: Added regex pattern support in
oneOf,allOf, andanyOfarrays usingregex:prefix - Enhancement: Made configuration fields optional with sensible defaults (
nullable,void,objectTypePattern) - Enhancement: Added configuration normalization to handle missing fields gracefully
🔧 Configuration Improvements
- Backward Compatibility: All existing configurations continue to work without changes
- Flexible Configuration: Minimal configurations now work without requiring all fields
- Regex Support: Can use patterns like
'regex:/^App\\Entity\\/'to match entity classes
🔧 Documentation Improvements
📚 Enhanced Method Must Return Type Rule Documentation
- New Examples: Added comprehensive examples for
oneOf,allOf, andanyOfusage - Regex Documentation: Added documentation for regex pattern support with examples
- Configuration Guide: Updated configuration examples to show new optional fields
- Usage Examples: Added real-world examples for entity validation and union types
📚 Updated Configuration Examples
- New Configuration Patterns: Added examples for minimal configurations
- Regex Examples: Added examples showing how to use regex patterns for class matching
- Union Type Examples: Added examples for both
oneOfandallOfscenarios
✅ New Test Cases
�� Comprehensive Test Coverage
- AnyOfRuleTest: Tests for the new
anyOffunctionality - RegexRuleTest: Tests for regex pattern matching in
anyOfarrays - RegexAllOfRuleTest: Tests for regex pattern matching in
allOfarrays - EntityRegexRuleTest: Tests for realistic entity pattern matching scenarios
- FacadeRuleTest: Tests for minimal configuration scenarios
- UnionTypeRuleTest: Tests for union type functionality
- Enhanced MethodMustReturnTypeRuleTest: Updated existing tests for new functionality
📁 New Test Data Files
data/MethodMustReturnType/AnyOfTestClass.php: Test cases foranyOffunctionalitydata/MethodMustReturnType/EntityRegexTestClass.php: Test cases for entity regex patternsdata/MethodMustReturnType/FacadeTestClass.php: Test cases for minimal configurationsdata/MethodMustReturnType/RegexAllOfTestClass.php: Test cases forallOfwith regexdata/MethodMustReturnType/RegexTestClass.php: Test cases for basic regex functionalitydata/MethodMustReturnType/UnionTypeTestClass.php: Test cases for union type validation
🏗️ Code Quality Improvements
🔧 Enhanced MethodMustReturnTypeRule
- New Methods: Added
normalizeConfig(),isTypeMatchWithRegex(),getExpectedTypeDescription() - Improved Error Handling: Better error messages for union types and regex patterns
- Code Organization: Better separation of concerns with dedicated methods for different validation types
- Type Safety: Enhanced type checking and validation logic
🐛 Bug Fixes
- Configuration Defaults: Fixed issues with missing configuration fields causing errors
- Regex Pattern Handling: Proper boolean conversion for regex pattern matching
- Union Type Parsing: Improved union type parsing and validation logic
- Error Message Consistency: Standardized error message formatting
📊 Statistics
- 16 files changed with 700+ lines added and 33 lines removed
- 17 new test files created for comprehensive coverage
- 100% backward compatibility maintained with existing configurations
🚀 Migration Guide
For Existing Users
No changes required! All existing configurations will continue to work exactly as before.
For New Features
To use the new union type functionality:
- class: Phauthentic\PHPStanRules\Architecture\MethodMustReturnTypeRule arguments: returnTypePatterns: - pattern: '/^MyClass::getValue$/' anyOf: ['int', 'string', 'bool'] - pattern: '/^MyClass::getEntity$/' anyOf: ['regex:/^App\\Entity\\/', 'void'] tags: - phpstan.rules.ruleThis release significantly enhances the flexibility and power of the Method Must Return Type Rule while maintaining full backward compatibility.
1.1.0
Release Notes
🎉 New Features
✨ New Rule: Catch Exception of Type Not Allowed Rule
- Class:
Phauthentic\PHPStanRules\Architecture\CatchExceptionOfTypeNotAllowedRule - Purpose: Prevents catching overly broad exception types like
Exception,Error, orThrowable - Configuration: Accepts an array of forbidden exception types
- Example: Configure to prevent catching
Exception,Error, orThrowablefor better error handling practices
✨ Enhanced Method Signature Must Match Rule
- New Feature: Added visibility scope validation
- New Feature: Improved parameter validation with optional type checking
- Enhancement: Better error messages and validation logic
- Configuration: Now supports
visibilityScopeparameter (public, protected, private)
🔧 Documentation Improvements
📚 Fixed Class Name References
Updated all configuration examples to use correct class names:
ReadonlyClassRule→ClassMustBeReadonlyRuleFinalClassRule→ClassMustBeFinalRuleNamespaceClassPatternRule→ClassnameMustMatchPatternRule
📚 Added Missing Rule Documentation
- Methods Returning Bool Must Follow Naming Convention Rule: Complete documentation added with configuration examples
- Catch Exception of Type Not Allowed Rule: Full documentation with examples
📚 Enhanced Documentation Structure
- Added anchor links to all rule sections for better navigation
- Improved README.md with clearer examples
- Updated namespace references from
Phauthentic\PhpstanRulestoPhauthentic\PHPStanRules
✅ New Test Cases
- CatchExceptionOfTypeNotAllowedRuleTest: Comprehensive tests for the new exception catching rule
- Enhanced MethodSignatureMustMatchRuleTest: Additional test cases for visibility scope and parameter validation
📁 New Test Data Files
data/CatchExceptionOfTypeNotAllowed/CatchAllowedException.php: Examples of allowed exception catchingdata/CatchExceptionOfTypeNotAllowed/CatchForbiddenException.php: Examples of forbidden exception catching- Enhanced
data/MethodSignatureMustMatch/TestClass.php: Additional test methods for validation
🏗️ Code Quality Improvements
🔧 Refactoring
- MethodSignatureMustMatchRule: Improved code structure with better separation of concerns
- MethodMustReturnTypeRule: Enhanced documentation and code comments
- phpstan.neon: Removed hardcoded rule configurations (now serves as a clean template)
🐛 Bug Fixes
- Fixed namespace casing inconsistencies (
PhpstanRules→PHPStanRules) - Improved parameter validation logic in MethodSignatureMustMatchRule
- Enhanced error message formatting and consistency
1.0.0 - Initial Release
Adding Signature and Return Type checking Rules (#4) * Adding rules to check return type and method signature * Adding a rule for naming methods that return booleans