-
-
Notifications
You must be signed in to change notification settings - Fork 149
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
Validators: added isListOfType() #123
Conversation
You either need to rename the method to |
I would expect this method to support objects as well: Validators::isIterableOfType($items, Product::class); For inspiration:
|
I thought about it but decided the object should implement Travarsable if you want to iterate through its properties. As is in new php7.1 function is_iterable. |
@TomasVotruba I think that the example you've posted should work just fine with the current implementation. |
What about |
@JanTvrdik Ah, that is missing in tests, that suggest only scalar types are supported. @t0his Could you please add test for simple object check? Sth like: test(function () {
Assert::true(Validators::isIterableOfType([new Product], Product::class));
Assert::false(Validators::isIterableOfType([new Product, new stdClass], Product::class));
}); |
@TomasVotruba Sure i can add it, but shouldnt this be covered by is() tests? @dg Ok i can rename it once i get home. |
It was only a suggestion, hold on. |
@t0his Most part of the test is already covered by is(), but that's not the goal. |
@TomasVotruba Ok would you like to add some other use case? |
Maybe extract method |
But the method will soon be redundant with php7.1. |
Yes, the method would use |
@t0his Nope, I guess that's all I would expect this method to do. Thank you. |
*/ | ||
private static function isIterable($value) | ||
{ | ||
if (function_exists('is_iterable')) { |
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.
Please use simply return is_array($value) || $value instanceof \Traversable;
, function_exists is unnecessary complication.
I would like to resolve #119.