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.