Skip to content

Commit

Permalink
style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
johnylemon89 committed Nov 19, 2020
1 parent 21621c7 commit 174c0e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 6 additions & 9 deletions src/Illuminate/Collections/Arr.php
Expand Up @@ -688,22 +688,19 @@ public static function wrap($value)
*/
public static function sortByMany($array, $comparisons = [])
{
usort($array, function($a, $b) use($comparisons) {

foreach($comparisons as $cmp)
{
usort($array, function ($a, $b) use ($comparisons) {
foreach ($comparisons as $cmp) {
// destruct comparison array to variables
// with order set by default to 1
[$prop, $ascending] = static::wrap($cmp) + [1 => true];
$result = 0;

if(is_callable($prop)) {
if (is_callable($prop)) {
$result = $prop($a, $b);
}
else {
} else {
$values = [static::get($a, $prop), static::get($b, $prop)];

if(!$ascending) {
if (! $ascending) {
$values = array_reverse($values);
}

Expand All @@ -712,7 +709,7 @@ public static function sortByMany($array, $comparisons = [])

// if result is 0, values are equal
// so we have to order items by next comparison
if($result === 0) {
if ($result === 0) {
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Support/SupportArrTest.php
Expand Up @@ -941,10 +941,10 @@ public function testSortByMany()

// sort using callable
$sortedWithCallable = array_values(Arr::sortByMany($unsorted, [
function($a, $b) {
function ($a, $b) {
return $a['name'] <=> $b['name'];
},
function($a, $b) {
function ($a, $b) {
return $b['age'] <=> $a['age'];
},
['meta.key', true],
Expand Down

0 comments on commit 174c0e5

Please sign in to comment.