Skip to content

Commit

Permalink
Laravel 5.6.12 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed Mar 15, 2018
1 parent 127547e commit 0dfca0b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions src/Support/Arr.php
Expand Up @@ -541,11 +541,20 @@ public static function set(&$array, $key, $value)
* Shuffle the given array and return the result.
*
* @param array $array
* @param int|null $seed
* @return array
*/
public static function shuffle($array)
public static function shuffle($array, $seed = null)
{
shuffle($array);
if (is_null($seed)) {
shuffle($array);
} else {
srand($seed);

usort($array, function () {
return rand(-1, 1);
});
}

return $array;
}
Expand Down
14 changes: 1 addition & 13 deletions src/Support/Collection.php
Expand Up @@ -1360,19 +1360,7 @@ public function shift()
*/
public function shuffle($seed = null)
{
$items = $this->items;

if (is_null($seed)) {
shuffle($items);
} else {
srand($seed);

usort($items, function () {
return rand(-1, 1);
});
}

return new static($items);
return new static(Arr::shuffle($this->items, $seed));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Str.php
Expand Up @@ -153,7 +153,7 @@ public static function finish($value, $cap)
*/
public static function is($pattern, $value)
{
$patterns = is_array($pattern) ? $pattern : (array) $pattern;
$patterns = Arr::wrap($pattern);

if (empty($patterns)) {
return false;
Expand Down
8 changes: 8 additions & 0 deletions tests/Support/SupportArrTest.php
Expand Up @@ -498,6 +498,14 @@ public function testSet()
$this->assertEquals(['products' => ['desk' => ['price' => 200]]], $array);
}

public function testShuffleWithSeed()
{
$this->assertEquals(
Arr::shuffle(range(0, 100, 10), 1234),
Arr::shuffle(range(0, 100, 10), 1234)
);
}

public function testSort()
{
$unsorted = [
Expand Down

0 comments on commit 0dfca0b

Please sign in to comment.