Respect / Validation

The most awesome validation engine ever created for PHP
https://respect-validation.readthedocs.io
MIT License
5.81k stars 772 forks source link

Allow building rules using prefixes #1453

Closed henriquemoody closed 8 months ago

henriquemoody commented 8 months ago

This PR introduce the allowing to create rules with the following prefixes.

I'm not so sure about that, and before I merge that to master, I thought about gathering some feedback first.

Here's how it will look like:

v::keyEquals('foo', 12)->assert(['foo' => 10]);
// foo must equal 12

v::propertyBetween('foo', 1, 3)->assert((object) ['foo' => 5]);
// foo must be between 1 and 3

v::lengthGreaterThan(3)->assert('foo');
// The length of "foo" must be greater than 3

v::maxOdd()->assert([1, 2, 3, 4]);
// As the maximum of `[1, 2, 3, 4]`, 4 must be an odd number

v::minEven()->assert([1, 2, 3]);
// As the minimum from `[1, 2, 3]`, 1 must be an even number

v::notBetween(1, 3)->assert(2);
// 2 must not be between 1 and 3

v::nullOrBoolType()->assert('string');
// "string" must be of type boolean

v::nullOrBoolType()->assert(null);
// 👆 doesn't throw any exception

v::undefOrUrl()->assert('string');
// "string" must be a URL

v::undefOrUrl()->assert(null);
// 👆 doesn't throw any exception

v::undefOrUrl()->assert('');
// 👆 doesn't throw any exception

Any thoughts?

codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 94.70%. Comparing base (9eafe52) to head (97b243d).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1453 +/- ## ============================================ + Coverage 94.65% 94.70% +0.04% - Complexity 950 962 +12 ============================================ Files 201 202 +1 Lines 2172 2189 +17 ============================================ + Hits 2056 2073 +17 Misses 116 116 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

henriquemoody commented 8 months ago

Still open for comments, of course. I can always revert the changes.