-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[11.x] Fluent Array validation #54517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11.x] Fluent Array validation #54517
Conversation
$this->keys = is_array($keys) ? $keys : func_get_args(); | ||
$keys = is_array($keys) ? $keys : func_get_args(); | ||
|
||
if (empty($keys)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could do this without a function call:
if (empty($keys)) { | |
if ($keys === []) { |
There was a problem hiding this comment.
Choose a reason for hidi 8000 ng this comment
The reason will be displayed to describe this comment to others. Learn more.
yes you are right i update it
$keys = array_map( | ||
static fn ($key) => enum_value($key), | ||
$keys, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simplify this to a first-class callable:
$keys = array_map( | |
static fn ($key) => enum_value($key), | |
$keys, | |
); | |
$keys = array_map(enum_value(..), $keys); |
I don't think this is adding much benefit. It feels like we're just adding more fluent rules for fun now. |
This pull request introduces a new fluent array validation class, offering a more elegant and expressive way to define array validation rules.
Before this PR, arrray validation required string-based rules:
To use the fluent array validation:
Available methods
distinct(bool $strict = false)
max(int $max)
min(int $min)
between(int $min, int $max)
size(int $size)
contains($keys)
inArray(string $anotherField)
list()