Skip to content

Introduce ContainsCount validator#1606

Merged
alganet merged 1 commit intomainfrom
containscount
Jan 15, 2026
Merged

Introduce ContainsCount validator#1606
alganet merged 1 commit intomainfrom
containscount

Conversation

@alganet
Copy link
Copy Markdown
Member

@alganet alganet commented Jan 15, 2026

This validator is similar to Contains, but also checks how many times the needle appears.

Additionally, the Domain validator was changed to use it instead of relying on an unserializable callback, thus, making it serializable.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.51%. Comparing base (4618996) to head (f5e22f1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1606      +/-   ##
============================================
+ Coverage     97.47%   97.51%   +0.03%     
- Complexity      993     1006      +13     
============================================
  Files           211      212       +1     
  Lines          2298     2334      +36     
============================================
+ Hits           2240     2276      +36     
  Misses           58       58              

☔ 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
Copy link
Copy Markdown
Member Author

alganet commented Jan 15, 2026

I wanted to make the $count parameter accept a wrapped validator, but I could not do it and also have template messages. I also found out some other validators don't have that, such as Between, so I decided to stop banging my head and just deliver the simpler version.

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 introduces a new ContainsCount validator that validates whether a value appears in a string or array exactly a specified number of times. The validator supports both case-insensitive (default) and identical comparisons. Additionally, the Domain validator has been updated to use ContainsCount instead of an unserializable callback, making the Domain validator serializable.

Changes:

  • Added new ContainsCount validator class with support for counting occurrences in strings and arrays
  • Updated Domain validator to use ContainsCount instead of a callback, making it serializable
  • Added comprehensive unit and feature tests for the new validator
  • Added documentation and updated cross-references

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
library/Validators/ContainsCount.php New validator class for checking exact occurrence count of a value
library/Validators/Domain.php Removed unserializable callback in favor of ContainsCount
library/Mixins/Chain.php Added containsCount method signature to Chain mixin
library/Mixins/Builder.php Added containsCount static method signature to Builder mixin
tests/unit/Validators/ContainsCountTest.php Unit tests for valid and invalid inputs
tests/feature/Validators/ContainsCountTest.php Feature tests for error messages
tests/benchmark/ValidatorBench.php Added benchmark cases for ContainsCount and Domain
docs/validators/ContainsCount.md Documentation for the new validator
docs/validators/index.md Updated index to include ContainsCount
docs/validators/Contains.md Added cross-reference to ContainsCount
docs/validators/ContainsAny.md Added cross-reference to ContainsCount

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread library/Validators/ContainsCount.php Outdated
Comment thread docs/validators/ContainsCount.md Outdated
Comment thread tests/feature/Validators/ContainsCountTest.php Outdated
Comment thread tests/feature/Validators/ContainsCountTest.php Outdated
@alganet alganet marked this pull request as ready for review January 15, 2026 07:20
@alganet alganet requested a review from henriquemoody January 15, 2026 07:21
henriquemoody
henriquemoody previously approved these changes Jan 15, 2026
Comment thread library/Validators/ContainsCount.php
Comment thread library/Mixins/Builder.php
Comment thread library/Validators/ContainsCount.php Outdated
This validator is similar to Contains, but also checks how many
times the needle appears.

Additionally, the Domain validator was changed to use it instead
of relying on an unserializable callback, thus, making it
serializable.
@alganet alganet merged commit 8e5938a into main Jan 15, 2026
11 checks passed
@alganet alganet deleted the containscount branch January 15, 2026 13:39
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