Skip to content

feat: Modernize PSR-4 implementation with PHP 8.1+ types#1

Merged
ralflang merged 3 commits intoFRAMEWORK_6_0from
feat/constraint-psr4-modernization
Mar 7, 2026
Merged

feat: Modernize PSR-4 implementation with PHP 8.1+ types#1
ralflang merged 3 commits intoFRAMEWORK_6_0from
feat/constraint-psr4-modernization

Conversation

@ralflang
Copy link
Member

@ralflang ralflang commented Mar 3, 2026

Modernizes Horde_Constraint with PHP 8.1+ type safety, fixes critical bugs, and provides complete test coverage.

Key changes:

  • Fix AndCoupler bug ($_constraints property)
  • Modern class names (AllOf, AnyOf, CompoundConstraint)
  • Full PHP 8.1+ type declarations (mixed, bool, readonly)
  • 40 PSR-4 tests (all pass)
  • Backward compatibility aliases
  • Complete documentation

Ready for Horde_Log to adopt PSR-4 constraints.

ralflang added 3 commits March 3, 2026 12:35
Modernize Horde_Constraint PSR-4 implementation with full type declarations,
consistent naming, and backward compatibility aliases.

Changes:
- Fix AndCoupler bug ($_constraints → $constraints)
- Rename Coupler → CompoundConstraint (base class)
- Add AllOf class (replaces AndCoupler implementation)
- Add AnyOf class (replaces OrCoupler implementation)
- Keep AndCoupler/OrCoupler/Coupler as BC aliases
- Add full PHP 8.1+ type declarations (mixed, bool, readonly)
- Update copyright years to 2026
- Improve PHPDoc with @param and @return
- Use readonly properties where appropriate
- Modern variadic constructor for CompoundConstraint

PSR-4 classes now:
- Constraint (interface) - evaluate(mixed): bool
- CompoundConstraint (abstract) - base for compound constraints
- AllOf - all constraints must pass (AND logic)
- AnyOf - any constraint must pass (OR logic)
- AlwaysTrue, AlwaysFalse - constant constraints
- IsEqual, IsInstanceOf, IsNull - comparison constraints
- Not - negation wrapper
- PregMatch - regex matching

Backward compatibility:
- AndCoupler extends AllOf (deprecated)
- OrCoupler extends AnyOf (deprecated)
- Coupler extends CompoundConstraint (deprecated)

For Horde_Log migration path.
Add complete test coverage for PSR-4 constraint implementations.

Changes:
- Update PHPUnit to 11.5 with modern configuration
- Update composer.json (PHP ^8.1, PHPUnit ^11.5, keywords)
- Create 9 PSR-4 test classes with 40 tests, 68 assertions
- Modern PHPUnit attributes (#[CoversClass])
- Separate test suites (psr4, psr0)
- Update bootstrap.php (remove Horde_Test dependency)

Test Coverage:
- AllOfTest (9 tests) - AND logic, flattening, empty case
- AnyOfTest (10 tests) - OR logic, short-circuit, flattening
- AlwaysTrueTest (1 test) - constant true
- AlwaysFalseTest (1 test) - constant false
- IsEqualTest (5 tests) - loose comparison, null behavior
- IsInstanceOfTest (4 tests) - instanceof checks
- IsNullTest (2 tests) - null checking
- NotTest (4 tests) - negation, double negation
- PregMatchTest (4 tests) - regex matching, modifiers

All 40 PSR-4 tests pass on PHP 8.4.
Add complete documentation for PSR-4 modernization and package metadata updates.

Documentation:
- README.md (220 lines) - Quick start, all constraints, usage examples
- UPGRADING.md (280 lines) - Migration guide from PSR-0 to PSR-4
- doc/changelog.yml - Version 3.0.0alpha6 entry

Package Metadata:
- .horde.yml → 3.0.0alpha6, PHP ^8.1, enhanced description
- composer.json - Already updated in previous commits

README covers:
- Dual-stack architecture (PSR-0 + PSR-4)
- Quick start with examples
- All 11 constraint types documented
- Usage patterns (complex rules, filtering, fluent building)
- Architecture overview
- Migration guide from PSR-0
- Class mapping table

UPGRADING guide covers:
- Zero breaking changes guarantee
- PSR-4 API improvements (types, variadic, readonly)
- Optional migration path (BC aliases vs modern names)
- Horde_Log migration example
- Deprecation notices
- Testing strategies

Total documentation: 500+ lines
@ralflang ralflang requested a review from amulet1 March 3, 2026 14:53
@ralflang ralflang merged commit fa1feb7 into FRAMEWORK_6_0 Mar 7, 2026
0 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant