Skip to content

Refactor case sensitiveness support#1645

Merged
alganet merged 1 commit intoRespect:mainfrom
alganet:case-sensitiveness.md
Jan 30, 2026
Merged

Refactor case sensitiveness support#1645
alganet merged 1 commit intoRespect:mainfrom
alganet:case-sensitiveness.md

Conversation

@alganet
Copy link
Copy Markdown
Member

@alganet alganet commented Jan 29, 2026

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.12%. Comparing base (7876576) to head (9634c25).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alganet alganet force-pushed the case-sensitiveness.md branch 3 times, most recently from f7fdfdc to b421338 Compare January 29, 2026 23:52
@alganet alganet requested a review from Copilot January 29, 2026 23:57
Copy link
Copy Markdown

Copilot AI left a comment

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 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 $identical parameter from validators (Contains, ContainsAny, ContainsCount, StartsWith, EndsWith, In), making all comparisons case-sensitive and strictly typed by default
  • Simplified the Call validator by removing error handling capabilities
  • Added new documentation explaining how to achieve case-insensitive validation using Call and Lazy validators
  • 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 true as 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>.

Comment thread tests/unit/Validators/ContainsTest.php Outdated
Comment thread tests/unit/Validators/ContainsTest.php Outdated
Comment thread tests/unit/Validators/StartsWithTest.php
Comment thread tests/unit/Validators/ContainsTest.php Outdated
Comment thread tests/unit/Validators/ContainsAnyTest.php Outdated
Comment thread docs/validators/Call.md Outdated
Comment thread src/Validators/Call.php Outdated
Comment thread docs/case-sensitiveness.md
Comment thread docs/validators/Contains.md Outdated
Comment thread tests/unit/Validators/ContainsTest.php Outdated
@alganet alganet force-pushed the case-sensitiveness.md branch 2 times, most recently from e1045a8 to 8115ec3 Compare January 30, 2026 00:13
@alganet alganet marked this pull request as ready for review January 30, 2026 00:15
@alganet alganet requested a review from henriquemoody January 30, 2026 00:15
@alganet alganet force-pushed the case-sensitiveness.md branch 3 times, most recently from 2bb5564 to 77500e9 Compare January 30, 2026 00:31
Copy link
Copy Markdown
Member

@henriquemoody henriquemoody left a comment

Choose a reason for hiding this comment

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

I love those changes!

Could you also update the migration guide? It's important information to be there.

Comment thread docs/validators/Call.md
Comment thread src/Validators/Call.php
Comment thread src/Validators/ContainsAny.php Outdated
Comment thread src/Validators/Tld.php
Comment thread tests/unit/Validators/CallTest.php
Comment thread docs/validators/Call.md Outdated
Comment thread src/Validators/Call.php Outdated
@alganet alganet force-pushed the case-sensitiveness.md branch 2 times, most recently from b7e8ce7 to 7c1e05e Compare January 30, 2026 14:02
@alganet alganet requested a review from henriquemoody January 30, 2026 14:04
Comment thread docs/validators/Call.md Outdated
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.
@alganet alganet force-pushed the case-sensitiveness.md branch from 7c1e05e to 9634c25 Compare January 30, 2026 16:04
@alganet alganet merged commit ec16b3d into Respect:main Jan 30, 2026
7 checks passed
@alganet alganet deleted the case-sensitiveness.md branch January 30, 2026 17:11
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.

3 participants