Refactor case sensitiveness support#1645
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1645 +/- ##
============================================
- Coverage 99.14% 99.12% -0.02%
+ Complexity 962 943 -19
============================================
Files 197 197
Lines 2215 2179 -36
============================================
- Hits 2196 2160 -36
Misses 19 19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
f7fdfdc to
b421338
Compare
There was a problem hiding this comment.
Pull request overview
This pull request refactors case-sensitivity support across multiple validators by removing the confusing $identical parameter and establishing a consistent case-sensitive default behavior. The refactor also simplifies the Call validator by removing error handling, shifting that responsibility to users via the Circuit validator or closures.
Changes:
- Removed the
$identicalparameter from validators (Contains,ContainsAny,ContainsCount,StartsWith,EndsWith,In), making all comparisons case-sensitive and strictly typed by default - Simplified the
Callvalidator by removing error handling capabilities - Added new documentation explaining how to achieve case-insensitive validation using
CallandLazyvalidators - Updated all mixin interfaces to reflect the removed parameters
Reviewed changes
Copilot reviewed 49 out of 49 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Validators/Contains.php | Removed $identical parameter, now always uses strict comparison |
| src/Validators/ContainsAny.php | Removed $identical parameter propagation |
| src/Validators/ContainsCount.php | Removed $identical parameter, simplified implementation |
| src/Validators/StartsWith.php | Removed $identical parameter and case-insensitive logic |
| src/Validators/EndsWith.php | Removed $identical parameter and case-insensitive logic |
| src/Validators/In.php | Removed $compareIdentical parameter, now always uses strict comparison |
| src/Validators/Call.php | Removed error handling, simplified to just call and validate |
| src/Validators/Tld.php | Updated to use Circuit validator for type checking |
| src/Mixins/*.php | Updated all mixin signatures to remove parameters |
| tests/unit/Validators/*.php | Updated test cases to reflect new behavior |
| tests/feature/Validators/*.php | Updated feature tests to remove parameter usage |
| docs/validators/*.md | Updated documentation to reflect API changes |
| docs/case-sensitiveness.md | New documentation for case-insensitive validation patterns |
Comments suppressed due to low confidence (1)
docs/validators/ContainsCount.md:32
- The documentation still includes an example using the old three-parameter signature with
trueas a third parameter. This parameter has been removed in the refactor, so these code examples are now invalid and will not work with the new API.
```php
v::containsCount(1, 1, true)->assert([1, 2, 3]);
// Validation passes successfully
v::containsCount('1', 1, true)->assert([1, 2, 3]);
// → `[1, 2, 3]` must contain "1" only once
</details>
---
💡 <a href="/Respect/Validation/new/2.4/.github/instructions?filename=*.instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add Copilot custom instructions</a> for smarter, more guided reviews. <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn how to get started</a>.
e1045a8 to
8115ec3
Compare
2bb5564 to
77500e9
Compare
henriquemoody
left a comment
There was a problem hiding this comment.
I love those changes!
Could you also update the migration guide? It's important information to be there.
b7e8ce7 to
7c1e05e
Compare
This is a mid-size refactor that affects several validators. Most prominently, the ones that had an `$identical` parameter to deal with case sensitiveness. This parameter was confusing, effectively making validators such as `Contains` behave very differently for arrays versus strings. In arrays, `$identical` meant "the same type", while it in strings it meant "case sensitive". That parameter was removed, and the default behavior is now to always compare **case sensitive** and strict typing. A document explaining how to combine other validators in order to achieve case _insensitive_ comparisons was added. Additionally, the `Call` validator was refactored back to be suitable to take on the task of being a fast, quick composable validator. With the introduction of `Circuit`, we can shift the responsibility of dealing with possible mismatches to the user. This kind of type handling is demonstrated in how I refactored `Tld` to account for the type mismatch without setting error handlers.
7c1e05e to
9634c25
Compare
This is a mid-size refactor that affects several validators.
Most prominently, the ones that had an
$identicalparameter to deal with case sensitiveness.This parameter was confusing, effectively making validators such as
Containsbehave very differently for arrays versus strings.In arrays,
$identicalmeant "the same type", while it in strings it meant "case sensitive".That parameter was removed, and the default behavior is now to always compare case sensitive and strict typing.
A document explaining how to combine other validators in order to achieve case insensitive comparisons was added.
Additionally, the
Callvalidator was refactored back to be suitable to take on the task of being a fast, quick composable validator.With the introduction of
Circuit, we can shift the responsibility of dealing with possible mismatches to the user. This kind of type handling is demonstrated in how I refactoredTldto account for the type mismatch without setting error handlers.