@@ -204,6 +204,10 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /* Wraps a callable with the purpose of fixing bad PHP sort implementations */ |
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param Closure $callable |
|
| 210 | + */ |
|
| 207 | 211 | private static function wrapCallable($callable) |
| 208 | 212 | { |
| 209 | 213 | $direction = Arrgh::getSortDirection(); |
@@ -215,6 +219,10 @@ discard block |
||
| 215 | 219 | } |
| 216 | 220 | |
| 217 | 221 | /* Transforms the incoming calls to native calls */ |
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @param Arrgh $object |
|
| 225 | + */ |
|
| 218 | 226 | private static function invoke($method, $args, $object = null) |
| 219 | 227 | { |
| 220 | 228 | self::getSortDirection(); |
@@ -651,7 +659,7 @@ discard block |
||
| 651 | 659 | * Partion the input based on the result of the callback function. |
| 652 | 660 | * |
| 653 | 661 | * @param array $array A collection |
| 654 | - * @param Closeure $callable A callable returning true or false depending on which way to partion the element—left or right. |
|
| 662 | + * @param Closure $callable A callable returning true or false depending on which way to partion the element—left or right. |
|
| 655 | 663 | * @return array An array with two arrays—left and right: [left, right] |
| 656 | 664 | */ |
| 657 | 665 | private static function arrgh_partition($array, $callable) |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | /* Returns an array */ |
| 62 | 62 | public function toArray() |
| 63 | 63 | { |
| 64 | - $array = array_map(function ($item) { |
|
| 64 | + $array = array_map(function($item) { |
|
| 65 | 65 | if ($item instanceof Arrgh) { |
| 66 | 66 | return $item->toArray(); |
| 67 | 67 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | private static function wrapCallable($callable) |
| 208 | 208 | { |
| 209 | 209 | $direction = Arrgh::getSortDirection(); |
| 210 | - return function ($a, $b) use ($direction, $callable) { |
|
| 210 | + return function($a, $b) use ($direction, $callable) { |
|
| 211 | 211 | $result = $callable($a, $b); |
| 212 | 212 | if ($result === 0) return $direction; |
| 213 | 213 | return $result; |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | $function_name = $snake; |
| 224 | 224 | $function_name_prefixed = stripos($method, "array_") === 0 ? $snake : "array_" . $snake; |
| 225 | 225 | |
| 226 | - $all_function_names = [ $function_name, $function_name_prefixed ]; |
|
| 226 | + $all_function_names = [$function_name, $function_name_prefixed]; |
|
| 227 | 227 | $all_functions = self::allFunctions(); |
| 228 | 228 | |
| 229 | 229 | $matching_handler = null; |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | // asort in PHP5 reverses equals ("arsort" doen't mess up for some reason) |
| 247 | 247 | if ($matching_function === "asort") { |
| 248 | 248 | $matching_function = "uasort"; |
| 249 | - array_push($args, function ($a, $b) { return strcasecmp($a, $b); }); |
|
| 249 | + array_push($args, function($a, $b) { return strcasecmp($a, $b); }); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | // Native array_column filters away null values. That means you cannot |
@@ -260,15 +260,15 @@ discard block |
||
| 260 | 260 | $column_key = $args[1]; |
| 261 | 261 | if (count($args) === 3) { |
| 262 | 262 | $column_id = $args[2]; |
| 263 | - $column_ids_new = array_map(function ($item) use ($column_id) { |
|
| 263 | + $column_ids_new = array_map(function($item) use ($column_id) { |
|
| 264 | 264 | return isset($item[$column_id]) ? $item[$column_id] : null; |
| 265 | 265 | }, $column_array); |
| 266 | - $post_handler = function ($result) use ($column_ids_new) { |
|
| 266 | + $post_handler = function($result) use ($column_ids_new) { |
|
| 267 | 267 | return array_combine($column_ids_new, $result); |
| 268 | 268 | }; |
| 269 | 269 | } |
| 270 | 270 | $args = [$column_array]; |
| 271 | - array_push($args, function ($item) use ($column_key) { |
|
| 271 | + array_push($args, function($item) use ($column_key) { |
|
| 272 | 272 | return isset($item[$column_key]) ? $item[$column_key] : null; |
| 273 | 273 | }); |
| 274 | 274 | } |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | |
| 281 | 281 | // If some arrays are Arrghs map to array or if callable, wrap it in new callable with |
| 282 | 282 | // info about sort direction. |
| 283 | - $args = array_map(function ($arg) use ($matching_function) { |
|
| 283 | + $args = array_map(function($arg) use ($matching_function) { |
|
| 284 | 284 | if ($arg instanceof Arrgh) { |
| 285 | 285 | return $arg->array; |
| 286 | 286 | } else if ($arg instanceof Closure) { |
@@ -407,14 +407,14 @@ discard block |
||
| 407 | 407 | return $array; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - $column = array_map(function ($item) use ($key) { return isset($item[$key]) ? $item[$key] : null; }, $array); |
|
| 410 | + $column = array_map(function($item) use ($key) { return isset($item[$key]) ? $item[$key] : null; }, $array); |
|
| 411 | 411 | array_multisort($column, ($direction_int === 1 ? SORT_ASC : SORT_DESC), $array); |
| 412 | 412 | return $array; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | private static function arrgh_collapse($array) |
| 416 | 416 | { |
| 417 | - return array_reduce($array, function ($merged, $item) { |
|
| 417 | + return array_reduce($array, function($merged, $item) { |
|
| 418 | 418 | if (is_array($item)) { |
| 419 | 419 | return array_merge($merged, $item); |
| 420 | 420 | } |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | if ($key) { |
| 430 | 430 | $haystack = array_column($array, $key); |
| 431 | 431 | } else { |
| 432 | - $haystack = array_reduce($array, function ($merged, $item) { |
|
| 432 | + $haystack = array_reduce($array, function($merged, $item) { |
|
| 433 | 433 | return array_merge($merged, array_values($item)); |
| 434 | 434 | }, []); |
| 435 | 435 | } |
@@ -439,13 +439,13 @@ discard block |
||
| 439 | 439 | private static function arrgh_except($array, $except) |
| 440 | 440 | { |
| 441 | 441 | if (is_string($except)) { |
| 442 | - $except = [ $except ]; |
|
| 442 | + $except = [$except]; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | $is_collection = Arrgh::arrgh_is_collection($array); |
| 446 | - $array = $is_collection ? $array : [ $array ]; |
|
| 446 | + $array = $is_collection ? $array : [$array]; |
|
| 447 | 447 | |
| 448 | - $result = array_map(function ($item) use ($except) { |
|
| 448 | + $result = array_map(function($item) use ($except) { |
|
| 449 | 449 | foreach ($except as $key) { |
| 450 | 450 | unset($item[$key]); |
| 451 | 451 | } |
@@ -461,13 +461,13 @@ discard block |
||
| 461 | 461 | private static function arrgh_only($array, $only) |
| 462 | 462 | { |
| 463 | 463 | if (is_string($only)) { |
| 464 | - $only = [ $only ]; |
|
| 464 | + $only = [$only]; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | $is_collection = Arrgh::arrgh_is_collection($array); |
| 468 | - $array = $is_collection ? $array : [ $array ]; |
|
| 468 | + $array = $is_collection ? $array : [$array]; |
|
| 469 | 469 | |
| 470 | - $result = array_map(function ($item) use ($only) { |
|
| 470 | + $result = array_map(function($item) use ($only) { |
|
| 471 | 471 | foreach ($item as $key => $value) { |
| 472 | 472 | if (!in_array($key, $only)) { |
| 473 | 473 | unset($item[$key]); |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | $next_node = $data; |
| 541 | 541 | } else { |
| 542 | 542 | if ($is_collection) { |
| 543 | - $next_node = array_map(function ($item) use ($next_key) { |
|
| 543 | + $next_node = array_map(function($item) use ($next_key) { |
|
| 544 | 544 | if ($item !== null && array_key_exists($next_key, $item)) { |
| 545 | 545 | return $item[$next_key]; |
| 546 | 546 | } |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | if ($collapse) { |
| 598 | 598 | $result[] = $partial; |
| 599 | 599 | } else { |
| 600 | - $result[] = [ $partial ]; |
|
| 600 | + $result[] = [$partial]; |
|
| 601 | 601 | } |
| 602 | 602 | } |
| 603 | 603 | } |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | |
| 641 | 641 | $depth = 0; |
| 642 | 642 | $child = array_shift($array); |
| 643 | - while(Arrgh::arrgh_is_collection($child)) { |
|
| 643 | + while (Arrgh::arrgh_is_collection($child)) { |
|
| 644 | 644 | $depth += 1; |
| 645 | 645 | $child = array_shift($child); |
| 646 | 646 | } |
@@ -658,24 +658,24 @@ discard block |
||
| 658 | 658 | { |
| 659 | 659 | $left = []; |
| 660 | 660 | $right = []; |
| 661 | - array_walk($array, function ($item, $key) use (&$left, &$right, $callable) { |
|
| 661 | + array_walk($array, function($item, $key) use (&$left, &$right, $callable) { |
|
| 662 | 662 | if ($callable($item, $key)) { |
| 663 | 663 | $left[] = $item; |
| 664 | 664 | } else { |
| 665 | 665 | $right[] = $item; |
| 666 | 666 | } |
| 667 | 667 | }); |
| 668 | - return [ $left, $right ]; |
|
| 668 | + return [$left, $right]; |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | private static function arrgh_even($array) |
| 672 | 672 | { |
| 673 | - return Arrgh::arrgh_partition($array, function ($item, $key) { return $key % 2 === 0; })[0]; |
|
| 673 | + return Arrgh::arrgh_partition($array, function($item, $key) { return $key % 2 === 0; })[0]; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | private static function arrgh_odd($array) |
| 677 | 677 | { |
| 678 | - return Arrgh::arrgh_partition($array, function ($item, $key) { return $key % 2 === 1; })[0]; |
|
| 678 | + return Arrgh::arrgh_partition($array, function($item, $key) { return $key % 2 === 1; })[0]; |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | /* Synonym of shift */ |