Add basic named filters to collections filterBy() method - #733
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request enhances the filtering functionality in collections by introducing named filters and expanding comparison capabilities. The changes allow for more expressive and flexible filtering operations beyond simple equality checks.
- Adds new comparison methods to the
Constraintclass for various numeric comparisons - Modifies the
filterBymethod to support named filter operations like 'greaterThan', 'lessThan', etc. - Implements validation to prevent incorrect usage of callable filters with extra arguments
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| formwork/src/Utils/Constraint.php | Adds five new static comparison methods for numeric and equality operations |
| formwork/src/Data/AbstractCollection.php | Refactors filterBy method to support named filters with match statement and parameter validation |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces enhancements to the filtering functionality in the
AbstractCollectionclass and adds new comparison methods to theConstraintutility class. The changes improve the flexibility and readability of filtering operations by supporting various comparison types and adding corresponding utility methods.Enhancements to filtering functionality:
filterBymethod inAbstractCollectionto support multiple comparison types (e.g.,equalTo,greaterThan,lessThan) using amatchstatement. This change replaces the previous implementation and introduces a more structured approach for handling comparisons.filterBymethod.New comparison methods in
Constraint:isNotEqualTo,isGreaterThan,isGreaterThanOrEqualTo,isLessThan, andisLessThanOrEqualToto theConstraintclass to support the new filtering capabilities. These methods provide reusable logic for performing various comparisons.