Skip to content

Releases: Phauthentic/phpstan-rules

1.4.0

29 Oct 23:49
bcff346

Choose a tag to compare

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

1.2.1

14 Aug 09:56
63f69df

Choose a tag to compare

Release Notes

🐛 Bug Fixes

Final Class Rule

  • Fixed: Abstract classes are now properly ignored by default to prevent false positives
  • Added: Configurable ignoreAbstractClasses parameter (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.rule

Backward Compatible: All existing configurations continue to work without changes.

1.2.0: Improving the MethodMustReturnType to support unions (#7)

29 Jul 13:30
23e5d35

Choose a tag to compare

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: true approach
  • New Feature: Added oneOf functionality for union types - allows specifying an array of types where one must match
  • New Feature: Added allOf functionality for union types - allows specifying an array of types where all must be present
  • New Feature: Added anyOf as an alias for oneOf for better readability
  • New Feature: Added regex pattern support in oneOf, allOf, and anyOf arrays using regex: 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, and anyOf usage
  • 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 oneOf and allOf scenarios

✅ New Test Cases

�� Comprehensive Test Coverage

  • AnyOfRuleTest: Tests for the new anyOf functionality
  • RegexRuleTest: Tests for regex pattern matching in anyOf arrays
  • RegexAllOfRuleTest: Tests for regex pattern matching in allOf arrays
  • 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 for anyOf functionality
  • data/MethodMustReturnType/EntityRegexTestClass.php: Test cases for entity regex patterns
  • data/MethodMustReturnType/FacadeTestClass.php: Test cases for minimal configurations
  • data/MethodMustReturnType/RegexAllOfTestClass.php: Test cases for allOf with regex
  • data/MethodMustReturnType/RegexTestClass.php: Test cases for basic regex functionality
  • data/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.rule

This release significantly enhances the flexibility and power of the Method Must Return Type Rule while maintaining full backward compatibility.

1.1.0

26 Jul 15:19
ba9dd3c

Choose a tag to compare

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, or Throwable
  • Configuration: Accepts an array of forbidden exception types
  • Example: Configure to prevent catching Exception, Error, or Throwable for 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 visibilityScope parameter (public, protected, private)

🔧 Documentation Improvements

📚 Fixed Class Name References

Updated all configuration examples to use correct class names:

  • ReadonlyClassRuleClassMustBeReadonlyRule
  • FinalClassRuleClassMustBeFinalRule
  • NamespaceClassPatternRuleClassnameMustMatchPatternRule

📚 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\PhpstanRules to Phauthentic\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 catching
  • data/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 (PhpstanRulesPHPStanRules)
  • Improved parameter validation logic in MethodSignatureMustMatchRule
  • Enhanced error message formatting and consistency

1.0.0 - Initial Release

22 Jul 21:12
921226b

Choose a tag to compare

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