Conversation
The Composite class didn't provide much value: just a constructor gathering validators and a getValidators() method that wasn't used. Because the Validator interface is so simple (only an evaluate method), it's not always worth creating abstract base classes that only provide constructor logic. Each composite validator can implement the interface directly with minimal duplication. Assisted-by: Opencode (GLM 4.7) Assisted-by: Claude Code (Opus 4.5)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1653 +/- ##
=========================================
Coverage 99.20% 99.21%
- Complexity 915 918 +3
=========================================
Files 191 190 -1
Lines 2146 2152 +6
=========================================
+ Hits 2129 2135 +6
Misses 17 17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This pull request removes the Composite abstract base class and updates all composite validators (AllOf, AnyOf, Circuit, NoneOf, OneOf) to implement the Validator interface directly. The Composite class provided minimal value, only offering constructor logic and an unused getValidators() method.
Changes:
- Removed the
Compositebase class and its associated test files - Updated five composite validators to implement
Validatordirectly with minimal duplication - Updated migration documentation to remove reference to
Compositebase class
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Validators/Core/Composite.php | Removed the abstract Composite base class |
| tests/unit/Validators/Core/CompositeTest.php | Removed tests for the now-deleted Composite class |
| tests/src/Validators/Core/ConcreteComposite.php | Removed test helper concrete implementation of Composite |
| src/Validators/AllOf.php | Now implements Validator directly with inline constructor and validators property |
| src/Validators/AnyOf.php | Now implements Validator directly with inline constructor and validators property |
| src/Validators/Circuit.php | Now implements Validator directly with inline constructor and validators property |
| src/Validators/NoneOf.php | Now implements Validator directly with inline constructor and validators property |
| src/Validators/OneOf.php | Now implements Validator directly with inline constructor and validators property |
| docs/migrating-from-v2-to-v3.md | Removed Composite from the list of available base classes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I'm not sure about this. That base class estabilished a common behavior across all logic-style composites (must have two arguments or more). This is different from what we discussed in #1650. I said:
I pointed out that the check for multiple parameters was spread out into two places: the new public When you said that didn't went unnoticed, I was expecting a PR that solves that issue, not just the name collision. With this change, this spread is further amplified to more classes. The abstract still exists "spiritually" (via the constructors having the exact same signature and implementation). If you ask an AI to refactor In broad strokes, what I was expecting was:
This would provide a clear class hierarchy with more general on the root and more specific on the leaves. It would still preserve the same behavior we have today. |
|
I was talking about the naming collision, not so much the problem you're describing. I'm sorry I wasn't clear enough 😕 As I mentioned in the commit message, I don't see much the point on keeping that abstract class just for the construtor. If PHP didn't have construtor inheritance, I wouldn't miss it, to be honest, and some languages like Java, C++, and C# don't even support it. The You know the contract of I know this is controversial amongst different engineers, maybe we're just on opposite sides here. |
We're PHP though!
And why is that bad? Reuse is good.
I don't understand what you mean here. Tools like phpstan depend heavily on constructor signatures, and do consider inheritance dynamics. PHP has traits, which are implementation only. The hierarchy mismatch I pointed out can be solved by using them as well.
Even on your side (constructors as unique pristine signatures), that doesn't solve the hierarchy mismatch I pointed out. IMHO, that problem is more offensive to OOP theory than variadic signatures. |
|
I think we see the We don't have a case for like
I think tools like PHPStan are a good example of what I'm saying, the way PHPStan checks if
Never said it's bad! I think |
|
Closed due recent changes in #1650 |
The Composite class didn't provide much value: just a constructor gathering validators and a getValidators() method that wasn't used.
Because the Validator interface is so simple (only an evaluate method), it's not always worth creating abstract base classes that only provide constructor logic. Each composite validator can implement the interface directly with minimal duplication.
Assisted-by: Opencode (GLM 4.7)
Assisted-by: Claude Code (Opus 4.5)