Skip to content

[5.4] Support amount 0 in Arr::random() - #20439

Merged
taylorotwell merged 9 commits into
laravel:5.4from
vlakoff:random
Aug 6, 2017
Merged

taylorotwell merged 9 commits into
laravel:5.4from
vlakoff:random

Conversation

@vlakoff

@vlakoff vlakoff commented Aug 5, 2017

Copy link
Copy Markdown
Contributor

Follow-up to #20396 and #20402.

To summarize:

  • Supports amount 0 in Arr::random() for consistency with Collection::random()
  • Supports "0" as a string, for consistency as the other numbers are accepted as strings.
  • A handful of additions to the tests, better this way to prevent any risk of regressions.


ping @browner12

@vlakoff vlakoff changed the title Random [5.4] Support amount 0 in Arr::random() Aug 5, 2017
vlakoff added 5 commits August 5, 2017 23:37
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.
@vlakoff

vlakoff commented Aug 6, 2017

Copy link
Copy Markdown
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 :)

@taylorotwell
taylorotwell merged commit 5d55936 into laravel:5.4 Aug 6, 2017
@vlakoff
vlakoff deleted the random branch August 7, 2017 01:06
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants