Skip to content

Releases: tommyknocker/struct

v1.2.0

26 Oct 03:24

Choose a tag to compare

🎉 Release v1.2.0: Attribute Helper Tool

🚀 Major Feature Release

This release introduces the Attribute Helper Tool - a powerful automation system that dramatically reduces boilerplate code when working with Struct classes.

What's New

Attribute Helper Tool

  • Automated Field attribute generation for Struct classes
  • Console interface similar to phpstan/php-cs-fixer for batch processing
  • Intelligent type inference for PHP properties (scalars, objects, arrays, union types)
  • Smart validation suggestions based on property names
  • Automatic alias generation for camelCase properties
  • Transformer recommendations (StringToUpper, StringToLower)
  • Default value inference based on property types and names

Developer Experience

  • Composer scripts for easy integration (composer struct-helper)
  • Comprehensive test suite with full coverage
  • Live examples demonstrating real-world usage
  • Custom exceptions for better error handling

🔧 Improvements

  • Removed phpstan-baseline.neon - all PHPStan Level 9 errors properly resolved
  • Enhanced type safety in AttributeHelper with proper Reflection type handling
  • Improved code quality by eliminating all static analysis warnings
  • Updated documentation with Attribute Helper section
  • Enhanced examples directory with Attribute Helper demonstrations

📊 Impact

  • 80% reduction in boilerplate code
  • Consistent attribute patterns across all Struct classes
  • Zero PHPStan errors at Level 9
  • 100% test coverage for new functionality

🛠️ Usage

# Generate attributes for a single file
php scripts/struct-helper.php src/UserProfile.php

# Process entire directory
php scripts/struct-helper.php src/

# Dry run to see what would change
php scripts/struct-helper.php --dry-run src/

# Using composer scripts
composer struct-helper src/
composer struct-helper-dry src/

📚 Documentation

  • Updated README.md with comprehensive Attribute Helper section
  • New examples: 09_attribute_helper_demo.php and 10_real_world_api_integration.php
  • Enhanced examples README with usage instructions

🧪 Testing

All tests pass:

  • ✅ 170 PHPUnit tests
  • ✅ 385 assertions
  • ✅ 93.37% code coverage
  • ✅ All examples working
  • ✅ PHPStan Level 9 clean
  • ✅ PSR-12 compliant

Full Changelog: v1.1.0...v1.2.0

v1.1.0

25 Oct 15:28

Choose a tag to compare

🚀 Struct v1.1.0 - Major Release

This release brings significant architectural improvements, new features, and enhanced developer experience to the Struct library.

✨ What's New

🏗️ Architectural Improvements

  • SOLID Principles: Complete refactoring following SOLID design principles
  • Performance Optimization: Reflection caching system for improved performance
  • Metadata System: Comprehensive metadata management with caching
  • Factory Pattern: Centralized struct creation with dependency injection support

🔧 New Features

  • Advanced Validation System: New ValidationRule interface with built-in rules
    • EmailRule - Email format validation
    • RangeRule - Numeric range validation
    • RequiredRule - Required field validation
  • Data Transformation System: TransformerInterface for data processing
    • StringToUpperTransformer - Convert strings to uppercase
    • StringToLowerTransformer - Convert strings to lowercase
  • Specialized Exception Handling:
    • ValidationException - Detailed validation errors
    • FieldNotFoundException - Missing field errors
  • Legacy Validator Support: Backward compatibility for existing validators

🧪 Testing & Quality

  • 90%+ Code Coverage: Comprehensive test suite with 139 tests
  • PHPStan Level 9: Maximum static analysis compliance
  • Automated Example Testing: New test-examples.sh script
  • Test Fixtures: Organized following "1 file - 1 class" principle

📚 Documentation & Examples

  • Enhanced README: Comprehensive documentation with real-world examples
  • New Examples: 8 detailed examples covering all features
  • Best Practices: Guidelines for effective library usage
  • Migration Guide: Clear upgrade path from previous versions

🔄 Breaking Changes

Field Attribute Changes

// Old (deprecated)
#[Field('string', validator: EmailValidator::class)]

// New (recommended)
#[Field('string', validationRules: [new EmailRule()])]

Exception Handling

// Old
try {
    $struct = new MyStruct($data);
} catch (RuntimeException $e) {
    // Handle error
}

// New
try {
    $struct = new MyStruct($data);
} catch (ValidationException $e) {
    echo "Field: " . $e->fieldName;
    echo "Value: " . $e->value;
} catch (FieldNotFoundException $e) {
    // Handle missing field
}

📊 Statistics

  • 61 files changed
  • 3,935 additions, 302 deletions
  • 139 tests (335 assertions)
  • 90%+ code coverage
  • PHPStan Level 9 compliance
  • PSR-12 coding standards

🛠️ Technical Details

New Classes & Interfaces

  • ValidationRule interface
  • TransformerInterface interface
  • ValidationResult class
  • FieldValidator class
  • MetadataFactory class
  • StructFactory class
  • JsonSerializer class
  • ReflectionCache class

Enhanced Features

  • Union type support
  • Advanced validation rules
  • Data transformation pipeline
  • Metadata caching system
  • Factory pattern implementation
  • Comprehensive error handling

🎯 Use Cases

Perfect for:

  • REST API validation with complex rules
  • Data Transfer Objects (DTOs) in clean architecture
  • Third-party API integration with field mapping
  • Form validation with data transformations
  • Enterprise applications with centralized creation
  • Data processing pipelines with automatic validation

📦 Installation

composer require tommyknocker/struct

🔗 Links

🙏 Contributors

Special thanks to all contributors who helped make this release possible!


Full Changelog: v1.0.0...v1.1.0