Skip to content

Add basic named filters to collections filterBy() method - #733

Merged
giuscris merged 5 commits into
2.xfrom
feature/collection-named-filters
Aug 7, 2025
Merged

Add basic named filters to collections filterBy() method#733
giuscris merged 5 commits into
2.xfrom
feature/collection-named-filters

Conversation

@giuscris

Copy link
Copy Markdown
Member

This pull request introduces enhancements to the filtering functionality in the AbstractCollection class and adds new comparison methods to the Constraint utility 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:

  • Modified the filterBy method in AbstractCollection to support multiple comparison types (e.g., equalTo, greaterThan, lessThan) using a match statement. This change replaces the previous implementation and introduces a more structured approach for handling comparisons.
  • Added validation to ensure no unexpected arguments are passed when using callable filters in the filterBy method.

New comparison methods in Constraint:

  • Added utility methods such as isNotEqualTo, isGreaterThan, isGreaterThanOrEqualTo, isLessThan, and isLessThanOrEqualTo to the Constraint class to support the new filtering capabilities. These methods provide reusable logic for performing various comparisons.

@giuscris giuscris added this to the 2.0.0 milestone Jul 19, 2025
@giuscris
giuscris requested a review from Copilot July 19, 2025 14:57
@giuscris giuscris self-assigned this Jul 19, 2025
@giuscris giuscris added the enhancement New feature or request label Jul 19, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Constraint class for various numeric comparisons
  • Modifies the filterBy method 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

Comment thread formwork/src/Data/AbstractCollection.php
Comment thread formwork/src/Data/AbstractCollection.php Outdated
Comment thread formwork/src/Data/AbstractCollection.php Outdated
Comment thread formwork/src/Utils/Constraint.php
giuscris and others added 3 commits July 26, 2025 15:39
@giuscris
giuscris merged commit 4af1dbc into 2.x Aug 7, 2025
1 check passed
@giuscris
giuscris deleted the feature/collection-named-filters branch August 7, 2025 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants