Validators: added isListOfType()#123
Validators: added isListOfType()#123dstrop wants to merge 6 commits intonette:masterfrom dstrop:master
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.
Please use simply return is_array($value) || $value instanceof \Traversable;, function_exists is unnecessary complication.
I would like to resolve #119.