You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And $collection contains fewer than 4 pages, I get an error:
array_rand(): Second argument has to be between 1 and the number of elements in the array
Maybe throwing an error is the right thing to do here, if I ask for 4 pages, maybe I should be able to always expect 4 pages. But a manual check in Collection#random that $num is smaller than the collection count, and a more user friendly error message if that's not the case, might be helpful!
The text was updated successfully, but these errors were encountered:
The error message seems pretty user friendly. The only problem is the random function itself isn't mentioned. If you pass a number larger than the count, should the function just silently change the number to count(array)?
if ($num > count($this->items)) {
$num = count($this->items);
}
If I do this:
And
$collection
contains fewer than 4 pages, I get an error:Maybe throwing an error is the right thing to do here, if I ask for 4 pages, maybe I should be able to always expect 4 pages. But a manual check in
Collection#random
that$num
is smaller than the collection count, and a more user friendly error message if that's not the case, might be helpful!The text was updated successfully, but these errors were encountered: