@@ -114,8 +114,9 @@ discard block |
||
| 114 | 114 | protected function mergesort(array &$array, \Closure $cmp_function) |
| 115 | 115 | { |
| 116 | 116 | // Arrays of size < 2 require no action. |
| 117 | - if (count($array) < 2) |
|
| 118 | - return; |
|
| 117 | + if (count($array) < 2) { |
|
| 118 | + return; |
|
| 119 | + } |
|
| 119 | 120 | |
| 120 | 121 | // Split the array in half |
| 121 | 122 | $halfway = count($array) / 2; |
@@ -138,15 +139,18 @@ discard block |
||
| 138 | 139 | while ($ptr1 < count($array1) && $ptr2 < count($array2)) { |
| 139 | 140 | if (call_user_func($cmp_function, $array1[$ptr1], $array2[$ptr2]) < 1) { |
| 140 | 141 | $array[] = $array1[$ptr1++]; |
| 141 | - } |
|
| 142 | - else { |
|
| 142 | + } else { |
|
| 143 | 143 | $array[] = $array2[$ptr2++]; |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // Merge the remainder |
| 148 | - while ($ptr1 < count($array1)) $array[] = $array1[$ptr1++]; |
|
| 149 | - while ($ptr2 < count($array2)) $array[] = $array2[$ptr2++]; |
|
| 148 | + while ($ptr1 < count($array1)) { |
|
| 149 | + $array[] = $array1[$ptr1++]; |
|
| 150 | + } |
|
| 151 | + while ($ptr2 < count($array2)) { |
|
| 152 | + $array[] = $array2[$ptr2++]; |
|
| 153 | + } |
|
| 150 | 154 | return; |
| 151 | 155 | } |
| 152 | 156 | } |