Completed
Push — master ( c43b67...867e3c )
by Michael
01:59
created
src/Arrgh.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
207 207
     private static function wrapCallable($callable)
208 208
     {
209 209
         $direction = self::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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 = self::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
 block discarded – undo
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 = self::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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
640 640
 
641 641
         $depth = 0;
642 642
         $child = array_shift($array);
643
-        while(self::arrgh_is_collection($child)) {
643
+        while (self::arrgh_is_collection($child)) {
644 644
             $depth += 1;
645 645
             $child = array_shift($child);
646 646
         }
@@ -658,24 +658,24 @@  discard block
 block discarded – undo
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 self::arrgh_partition($array, function ($item, $key) { return $key % 2 === 0; })[0];
673
+        return self::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 self::arrgh_partition($array, function ($item, $key) { return $key % 2 === 1; })[0];
678
+        return self::arrgh_partition($array, function($item, $key) { return $key % 2 === 1; })[0];
679 679
     }
680 680
 
681 681
     /* Synonym of shift */
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -209,7 +209,9 @@  discard block
 block discarded – undo
209 209
         $direction = self::getSortDirection();
210 210
         return function ($a, $b) use ($direction, $callable) {
211 211
             $result = $callable($a, $b);
212
-            if ($result === 0) return $direction;
212
+            if ($result === 0) {
213
+                return $direction;
214
+            }
213 215
             return $result;
214 216
         };
215 217
     }
@@ -635,8 +637,12 @@  discard block
 block discarded – undo
635 637
      */
636 638
     private static function arrgh_depth($array)
637 639
     {
638
-        if (empty($array) && is_array($array)) return 0;
639
-        if (!self::arrgh_is_collection($array)) return null;
640
+        if (empty($array) && is_array($array)) {
641
+            return 0;
642
+        }
643
+        if (!self::arrgh_is_collection($array)) {
644
+            return null;
645
+        }
640 646
 
641 647
         $depth = 0;
642 648
         $child = array_shift($array);
Please login to merge, or discard this patch.