Skip to content

Releases: Phauthentic/phpstan-rules

1.2.1

14 Aug 09:56
63f69df
Compare
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
Compare
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
Compare
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
Compare
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