[5.4] Support amount 0 in Arr::random() - #20439
Merged
Merged
Conversation
I overlooked it, so I guess it's better to consolidate in one method.
For consistency with Collection::random()
Now redundant because Arr::random() supports it. DRY principle, and the case is covered by tests.
For consistency with other numbers, as they are accepted as strings.
Contributor
Author
|
Added a commit to remove the redundant "enough items available" validation code. I was tired of seeing this duplication only because the exception messages were slightly different :) |
salmanarshad321
pushed a commit
to salmanarshad321/framework
that referenced
this pull request
Sep 23, 2026
* Shorten name of variable * Move test to main method I overlooked it, so I guess it's better to consolidate in one method. * Rewrite to be more readable and safer with "0" value * Support amount 0 in Arr::random() For consistency with Collection::random() * Remove code for handling amount 0 in Collection::random() Now redundant because Arr::random() supports it. DRY principle, and the case is covered by tests. * Support amount '0' as a string in Arr and Collection random() For consistency with other numbers, as they are accepted as strings. * Add test cases when requesting too many items in random methods * Remove redundant validation code * Update Arr.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #20396 and #20402.
To summarize:
Arr::random()for consistency withCollection::random()ping @browner12