Skip to content

1.4.0

Choose a tag to compare

@floriankraemer floriankraemer released this 29 Oct 23:49
· 37 commits to master since this release
bcff346

πŸŽ‰ 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, and allowedCrossModulePatterns parameters
  • 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 baseNamespace parameter

✨ 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::methodName format 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, and requireListItemsEndWithPeriod parameters

✨ Enhanced Clean Code Rules

Too Many Arguments Rule - Pattern Support

  • Enhancement: Added optional patterns parameter to apply rule only to classes matching specific regex patterns
  • Backward Compatible: Existing configurations without patterns continue 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 ignoreUseStatements parameter 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 ignoreUseStatements parameter

πŸ“š Documentation Structure Improvements

  • Refactored Documentation: Moved all individual rule documentation from docs/Rules.md to individual files in docs/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.rule

For 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.rule

For 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.rule

To ignore use statements in Max Line Length Rule:

services:
    -
        class: Phauthentic\PHPStanRules\CleanCode\MaxLineLengthRule
        arguments:
            maxLineLength: 80
            ignoreUseStatements: true
        tags:
            - phpstan.rules.rule

This 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.