Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Arr::sort(): limited use of underlying Collection fixed #15050

Merged
merged 1 commit into from
Aug 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Illuminate/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,13 @@ public static function set(&$array, $key, $value)
}

/**
* Sort the array using the given callback.
* Sort the array using the given callback or "dot" notation.
*
* @param array $array
* @param callable $callback
* @param callable|string $callback
* @return array
*/
public static function sort($array, callable $callback)
public static function sort($array, $callback)
{
return Collection::make($array)->sortBy($callback)->all();
}
Expand Down
17 changes: 11 additions & 6 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,20 +358,25 @@ public function testSet()

public function testSort()
{
$array = [
$unsorted = [
['name' => 'Desk'],
['name' => 'Chair'],
];

$array = array_values(Arr::sort($array, function ($value) {
return $value['name'];
}));

$expected = [
['name' => 'Chair'],
['name' => 'Desk'],
];
$this->assertEquals($expected, $array);

// sort with closure
$sortedWithClosure = array_values(Arr::sort($unsorted, function ($value) {
return $value['name'];
}));
$this->assertEquals($expected, $sortedWithClosure);

// sort with dot notation
$sortedWithDotNotation = array_values(Arr::sort($unsorted, 'name'));
$this->assertEquals($expected, $sortedWithDotNotation);
}

public function testSortRecursive()
Expand Down