Releases: Phauthentic/phpstan-rules
1.4.0
🎉 New Features
✨ Modular Architecture Rules
New Rule: Modular Architecture Rule
- Class:
Phauthentic\PHPStanRules\Architecture\ModularArchitectureRule - Purpose: Enforces strict dependency rules for modular hexagonal (Ports and Adapters) architecture with capabilities/modules
- Key Features:
- Enforces intra-module layer dependencies (Domain, Application, Infrastructure, Presentation)
- Enforces cross-module dependencies using configurable regex patterns
- Supports custom layer dependency rules
- Configurable base namespace for capabilities/modules
- Configuration: Supports
baseNamespace,layerDependencies, andallowedCrossModulePatternsparameters - Example: Perfect for modular monoliths where each capability/module follows a layered architecture pattern
New Rule: Circular Module Dependency Rule
- Class:
Phauthentic\PHPStanRules\Architecture\CircularModuleDependencyRule - Purpose: Detects circular dependencies between modules in a modular architecture
- Key Features:
- Tracks module-to-module dependencies
- Reports circular dependency chains (e.g., Module A → Module B → Module C → Module A)
- Configurable base namespace for capabilities/modules
- Configuration: Requires
baseNamespaceparameter
✨ Specification Docblock Rule
New Rule: Class Must Have Specification Docblock Rule
- Class:
Phauthentic\PHPStanRules\Architecture\ClassMustHaveSpecificationDocblockRule - Purpose: Ensures that classes, interfaces, and/or methods matching specified patterns have a properly formatted docblock with a "Specification:" section
- Key Features:
- Validates classes and interfaces using regex patterns
- Validates methods using
FQCN::methodNameformat with regex patterns - Configurable specification header text (default: "Specification:")
- Optional requirement for blank line after header
- Optional requirement for list items to end with periods
- Supports annotations after specification section
- Configuration: Supports
classPatterns,methodPatterns,specificationHeader,requireBlankLineAfterHeader, andrequireListItemsEndWithPeriodparameters
✨ Enhanced Clean Code Rules
Too Many Arguments Rule - Pattern Support
- Enhancement: Added optional
patternsparameter to apply rule only to classes matching specific regex patterns - Backward Compatible: Existing configurations without
patternscontinue to work (applies to all classes) - Example: Can now configure to only check specific classes like
'/.*Service$/'or'/App\\Service\\/'
Max Line Length Rule - Use Statement Ignoring
- Enhancement: Added
ignoreUseStatementsparameter to optionally ignore use statement lines - Configuration: Boolean flag (default:
false) to exclude use statements from line length checking
📚 Documentation Improvements
📚 New Documentation Files
- Modular Architecture Rule: Complete documentation with examples for modular monolith architectures
- Circular Module Dependency Rule: Full documentation with configuration examples
- Class Must Have Specification Docblock Rule: Comprehensive documentation with multiple configuration examples for classes, interfaces, and methods
- Too Many Arguments Rule: Updated documentation with pattern support examples
- Max Line Length Rule: Updated documentation with
ignoreUseStatementsparameter
📚 Documentation Structure Improvements
- Refactored Documentation: Moved all individual rule documentation from
docs/Rules.mdto individual files indocs/rules/directory - Improved Navigation: Each rule now has its own dedicated documentation file for better discoverability
- Enhanced Examples: Added comprehensive configuration examples for all new rules
- Real-world Use Cases: Added practical examples for modular architecture setup
🚀 Migration Guide
For Existing Users
All existing configurations continue to work without changes. The new rules are opt-in and require explicit configuration.
For New Modular Architecture Features
To use the new modular architecture rules:
services:
-
class: Phauthentic\PHPStanRules\Architecture\ModularArchitectureRule
arguments:
baseNamespace: 'App\\Capability'
layerDependencies:
Domain: []
Application: [Domain]
Infrastructure: [Domain, Application]
Presentation: [Application]
allowedCrossModulePatterns:
- '/Facade$/'
- '/FacadeInterface$/'
- '/Input$/'
- '/Result$/'
tags:
- phpstan.rules.rule
-
class: Phauthentic\PHPStanRules\Architecture\CircularModuleDependencyRule
arguments:
baseNamespace: 'App\\Capability'
tags:
- phpstan.rules.ruleFor Specification Docblock Validation
To enforce specification docblocks:
services:
-
class: Phauthentic\PHPStanRules\Architecture\ClassMustHaveSpecificationDocblockRule
arguments:
classPatterns:
- '/.*Facade$/'
- '/.*Command$/'
methodPatterns:
- '/.*Repository::find.*/'
specificationHeader: 'Specification:'
requireBlankLineAfterHeader: true
requireListItemsEndWithPeriod: false
tags:
- phpstan.rules.ruleFor Enhanced Clean Code Rules
To use pattern matching with Too Many Arguments Rule:
services:
-
class: Phauthentic\PHPStanRules\CleanCode\TooManyArgumentsRule
arguments:
maxArguments: 3
patterns: ['/.*Service$/', '/App\\Controller\\/']
tags:
- phpstan.rules.ruleTo ignore use statements in Max Line Length Rule:
services:
-
class: Phauthentic\PHPStanRules\CleanCode\MaxLineLengthRule
arguments:
maxLineLength: 80
ignoreUseStatements: true
tags:
- phpstan.rules.ruleThis release significantly expands the capabilities of phpstan-rules, especially for teams working with modular monolith architectures and clean code practices, while maintaining full backward compatibility with existing configurations.
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