Completed
Push — master ( f8d6fe...92a23c )
by Lars
02:21
created
src/Arrayy.php 1 patch
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
       return false;
81 81
     }
82 82
 
83
-    return (array)$this->array;
83
+    return (array) $this->array;
84 84
   }
85 85
 
86 86
   /**
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
     }
296 296
 
297 297
     // php cast "bool"-index into "int"-index
298
-    if ((bool)$offset === $offset) {
299
-      $offset = (int)$offset;
298
+    if ((bool) $offset === $offset) {
299
+      $offset = (int) $offset;
300 300
     }
301 301
 
302 302
     $tmpReturn = \array_key_exists($offset, $this->array);
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
         (
308 308
             $tmpReturn === false
309 309
             &&
310
-            \strpos((string)$offset, $this->pathSeparator) === false
310
+            \strpos((string) $offset, $this->pathSeparator) === false
311 311
         )
312 312
     ) {
313 313
       return $tmpReturn;
@@ -315,16 +315,16 @@  discard block
 block discarded – undo
315 315
 
316 316
     $offsetExists = false;
317 317
 
318
-    if (\strpos((string)$offset, $this->pathSeparator) !== false) {
318
+    if (\strpos((string) $offset, $this->pathSeparator) !== false) {
319 319
 
320 320
       $offsetExists = false;
321
-      $explodedPath = \explode($this->pathSeparator, (string)$offset);
321
+      $explodedPath = \explode($this->pathSeparator, (string) $offset);
322 322
       $lastOffset = \array_pop($explodedPath);
323 323
       $containerPath = \implode($this->pathSeparator, $explodedPath);
324 324
 
325 325
       $this->callAtPath(
326 326
           $containerPath,
327
-          function ($container) use ($lastOffset, &$offsetExists) {
327
+          function($container) use ($lastOffset, &$offsetExists) {
328 328
             $offsetExists = \array_key_exists($lastOffset, $container);
329 329
           }
330 330
       );
@@ -377,14 +377,14 @@  discard block
 block discarded – undo
377 377
       return;
378 378
     }
379 379
 
380
-    if (\strpos((string)$offset, $this->pathSeparator) !== false) {
380
+    if (\strpos((string) $offset, $this->pathSeparator) !== false) {
381 381
 
382
-      $path = \explode($this->pathSeparator, (string)$offset);
382
+      $path = \explode($this->pathSeparator, (string) $offset);
383 383
       $pathToUnset = \array_pop($path);
384 384
 
385 385
       $this->callAtPath(
386 386
           \implode($this->pathSeparator, $path),
387
-          function (&$offset) use ($pathToUnset) {
387
+          function(&$offset) use ($pathToUnset) {
388 388
             unset($offset[$pathToUnset]);
389 389
           }
390 390
       );
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
     }
421 421
 
422 422
     if (\strpos($class, '\\') === 0) {
423
-      $class = '\\' . $class;
423
+      $class = '\\'.$class;
424 424
       if (\class_exists($class)) {
425 425
         $this->iteratorClass = $class;
426 426
 
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
       }
429 429
     }
430 430
 
431
-    throw new \InvalidArgumentException('The iterator class does not exist: ' . $class);
431
+    throw new \InvalidArgumentException('The iterator class does not exist: '.$class);
432 432
   }
433 433
 
434 434
   /**
@@ -493,11 +493,11 @@  discard block
 block discarded – undo
493 493
     $result = array();
494 494
     foreach ($this->array as $key => $item) {
495 495
       if ($item instanceof self) {
496
-        $result[$prefix . $key] = $item->appendToEachKey($prefix);
496
+        $result[$prefix.$key] = $item->appendToEachKey($prefix);
497 497
       } elseif (\is_array($item)) {
498
-        $result[$prefix . $key] = self::create($item)->appendToEachKey($prefix)->toArray();
498
+        $result[$prefix.$key] = self::create($item)->appendToEachKey($prefix)->toArray();
499 499
       } else {
500
-        $result[$prefix . $key] = $item;
500
+        $result[$prefix.$key] = $item;
501 501
       }
502 502
     }
503 503
 
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
       } elseif (\is_object($item)) {
523 523
         $result[$key] = $item;
524 524
       } else {
525
-        $result[$key] = $prefix . $item;
525
+        $result[$key] = $prefix.$item;
526 526
       }
527 527
     }
528 528
 
@@ -688,8 +688,8 @@  discard block
 block discarded – undo
688 688
   public function clean()
689 689
   {
690 690
     return $this->filter(
691
-        function ($value) {
692
-          return (bool)$value;
691
+        function($value) {
692
+          return (bool) $value;
693 693
         }
694 694
     );
695 695
   }
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
       return $this->in_array_recursive(
781 781
           UTF8::strtoupper($value),
782 782
           $this->walk(
783
-              function (&$val) {
783
+              function(&$val) {
784 784
                 $val = UTF8::strtoupper($val);
785 785
               },
786 786
               true
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
     return \in_array(
793 793
         UTF8::strtoupper($value),
794 794
         $this->walk(
795
-            function (&$val) {
795
+            function(&$val) {
796 796
               $val = UTF8::strtoupper($val);
797 797
             },
798 798
             false
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
     // trim all string in the array
997 997
     \array_walk(
998 998
         $array,
999
-        function (&$val) {
999
+        function(&$val) {
1000 1000
           /** @noinspection ReferenceMismatchInspection */
1001 1001
           if (\is_string($val)) {
1002 1002
             $val = \trim($val);
@@ -1235,7 +1235,7 @@  discard block
 block discarded – undo
1235 1235
     }
1236 1236
 
1237 1237
     if ($isObject && \method_exists($array, '__toArray')) {
1238
-      return (array)$array->__toArray();
1238
+      return (array) $array->__toArray();
1239 1239
     }
1240 1240
 
1241 1241
     /** @noinspection ReferenceMismatchInspection */
@@ -1244,7 +1244,7 @@  discard block
 block discarded – undo
1244 1244
         ||
1245 1245
         ($isObject && \method_exists($array, '__toString'))
1246 1246
     ) {
1247
-      return array((string)$array);
1247
+      return array((string) $array);
1248 1248
     }
1249 1249
 
1250 1250
     throw new \InvalidArgumentException(
@@ -1351,54 +1351,54 @@  discard block
 block discarded – undo
1351 1351
     }
1352 1352
 
1353 1353
     $ops = array(
1354
-        'eq'          => function ($item, $prop, $value) {
1354
+        'eq'          => function($item, $prop, $value) {
1355 1355
           return $item[$prop] === $value;
1356 1356
         },
1357
-        'gt'          => function ($item, $prop, $value) {
1357
+        'gt'          => function($item, $prop, $value) {
1358 1358
           return $item[$prop] > $value;
1359 1359
         },
1360
-        'ge'          => function ($item, $prop, $value) {
1360
+        'ge'          => function($item, $prop, $value) {
1361 1361
           return $item[$prop] >= $value;
1362 1362
         },
1363
-        'gte'         => function ($item, $prop, $value) {
1363
+        'gte'         => function($item, $prop, $value) {
1364 1364
           return $item[$prop] >= $value;
1365 1365
         },
1366
-        'lt'          => function ($item, $prop, $value) {
1366
+        'lt'          => function($item, $prop, $value) {
1367 1367
           return $item[$prop] < $value;
1368 1368
         },
1369
-        'le'          => function ($item, $prop, $value) {
1369
+        'le'          => function($item, $prop, $value) {
1370 1370
           return $item[$prop] <= $value;
1371 1371
         },
1372
-        'lte'         => function ($item, $prop, $value) {
1372
+        'lte'         => function($item, $prop, $value) {
1373 1373
           return $item[$prop] <= $value;
1374 1374
         },
1375
-        'ne'          => function ($item, $prop, $value) {
1375
+        'ne'          => function($item, $prop, $value) {
1376 1376
           return $item[$prop] !== $value;
1377 1377
         },
1378
-        'contains'    => function ($item, $prop, $value) {
1379
-          return \in_array($item[$prop], (array)$value, true);
1378
+        'contains'    => function($item, $prop, $value) {
1379
+          return \in_array($item[$prop], (array) $value, true);
1380 1380
         },
1381
-        'notContains' => function ($item, $prop, $value) {
1382
-          return !\in_array($item[$prop], (array)$value, true);
1381
+        'notContains' => function($item, $prop, $value) {
1382
+          return !\in_array($item[$prop], (array) $value, true);
1383 1383
         },
1384
-        'newer'       => function ($item, $prop, $value) {
1384
+        'newer'       => function($item, $prop, $value) {
1385 1385
           return \strtotime($item[$prop]) > \strtotime($value);
1386 1386
         },
1387
-        'older'       => function ($item, $prop, $value) {
1387
+        'older'       => function($item, $prop, $value) {
1388 1388
           return \strtotime($item[$prop]) < \strtotime($value);
1389 1389
         },
1390 1390
     );
1391 1391
 
1392 1392
     $result = \array_values(
1393 1393
         \array_filter(
1394
-            (array)$this->array,
1395
-            function ($item) use (
1394
+            (array) $this->array,
1395
+            function($item) use (
1396 1396
                 $property,
1397 1397
                 $value,
1398 1398
                 $ops,
1399 1399
                 $comparisonOp
1400 1400
             ) {
1401
-              $item = (array)$item;
1401
+              $item = (array) $item;
1402 1402
               $itemArrayy = new Arrayy($item);
1403 1403
               $item[$property] = $itemArrayy->get($property, array());
1404 1404
 
@@ -1471,9 +1471,9 @@  discard block
 block discarded – undo
1471 1471
   {
1472 1472
     if ($number === null) {
1473 1473
       $arrayTmp = $this->array;
1474
-      $array = (array)\array_shift($arrayTmp);
1474
+      $array = (array) \array_shift($arrayTmp);
1475 1475
     } else {
1476
-      $number = (int)$number;
1476
+      $number = (int) $number;
1477 1477
       $arrayTmp = $this->array;
1478 1478
       $array = \array_splice($arrayTmp, 0, $number, true);
1479 1479
     }
@@ -1491,9 +1491,9 @@  discard block
 block discarded – undo
1491 1491
   public function firstsMutable($number = null)
1492 1492
   {
1493 1493
     if ($number === null) {
1494
-      $this->array = (array)\array_shift($this->array);
1494
+      $this->array = (array) \array_shift($this->array);
1495 1495
     } else {
1496
-      $number = (int)$number;
1496
+      $number = (int) $number;
1497 1497
       $this->array = \array_splice($this->array, 0, $number, true);
1498 1498
     }
1499 1499
 
@@ -1525,7 +1525,7 @@  discard block
 block discarded – undo
1525 1525
   public function get($key, $fallback = null, $array = null)
1526 1526
   {
1527 1527
     if ($array !== null) {
1528
-      $usedArray = (array)$array;
1528
+      $usedArray = (array) $array;
1529 1529
     } else {
1530 1530
       $usedArray = $this->array;
1531 1531
     }
@@ -1535,8 +1535,8 @@  discard block
 block discarded – undo
1535 1535
     }
1536 1536
 
1537 1537
     // php cast "bool"-index into "int"-index
1538
-    if ((bool)$key === $key) {
1539
-      $key = (int)$key;
1538
+    if ((bool) $key === $key) {
1539
+      $key = (int) $key;
1540 1540
     }
1541 1541
 
1542 1542
     if (\array_key_exists($key, $usedArray) === true) {
@@ -1548,7 +1548,7 @@  discard block
 block discarded – undo
1548 1548
     }
1549 1549
 
1550 1550
     // Crawl through array, get key according to object or not
1551
-    foreach (\explode($this->pathSeparator, (string)$key) as $segment) {
1551
+    foreach (\explode($this->pathSeparator, (string) $key) as $segment) {
1552 1552
       if (!isset($usedArray[$segment])) {
1553 1553
         return $fallback instanceof \Closure ? $fallback() : $fallback;
1554 1554
       }
@@ -1720,7 +1720,7 @@  discard block
 block discarded – undo
1720 1720
    */
1721 1721
   public function group($grouper, $saveKeys = false)
1722 1722
   {
1723
-    $array = (array)$this->array;
1723
+    $array = (array) $this->array;
1724 1724
     $result = array();
1725 1725
 
1726 1726
     // Iterate over values, group by property/results from closure
@@ -1818,7 +1818,7 @@  discard block
 block discarded – undo
1818 1818
       );
1819 1819
     }
1820 1820
 
1821
-    return (string)$pieces;
1821
+    return (string) $pieces;
1822 1822
   }
1823 1823
 
1824 1824
   /**
@@ -1903,7 +1903,7 @@  discard block
 block discarded – undo
1903 1903
    */
1904 1904
   protected function internalRemove($key)
1905 1905
   {
1906
-    $path = \explode($this->pathSeparator, (string)$key);
1906
+    $path = \explode($this->pathSeparator, (string) $key);
1907 1907
 
1908 1908
     // Crawl though the keys
1909 1909
     while (\count($path) > 1) {
@@ -1938,8 +1938,8 @@  discard block
 block discarded – undo
1938 1938
     }
1939 1939
 
1940 1940
     // init
1941
-    $array =& $this->array;
1942
-    $path = \explode($this->pathSeparator, (string)$key);
1941
+    $array = & $this->array;
1942
+    $path = \explode($this->pathSeparator, (string) $key);
1943 1943
 
1944 1944
     // Crawl through the keys
1945 1945
     while (count($path) > 1) {
@@ -1952,7 +1952,7 @@  discard block
 block discarded – undo
1952 1952
         $array[$key] = static::create(array());
1953 1953
       }
1954 1954
 
1955
-      $array =& $array[$key];
1955
+      $array = & $array[$key];
1956 1956
     }
1957 1957
 
1958 1958
     $array[\array_shift($path)] = $value;
@@ -2233,12 +2233,12 @@  discard block
 block discarded – undo
2233 2233
       if ($poppedValue === null) {
2234 2234
         $poppedValue = array($poppedValue);
2235 2235
       } else {
2236
-        $poppedValue = (array)$poppedValue;
2236
+        $poppedValue = (array) $poppedValue;
2237 2237
       }
2238 2238
 
2239 2239
       $arrayy = static::create($poppedValue);
2240 2240
     } else {
2241
-      $number = (int)$number;
2241
+      $number = (int) $number;
2242 2242
       $arrayy = $this->rest(-$number);
2243 2243
     }
2244 2244
 
@@ -2264,12 +2264,12 @@  discard block
 block discarded – undo
2264 2264
       if ($poppedValue === null) {
2265 2265
         $poppedValue = array($poppedValue);
2266 2266
       } else {
2267
-        $poppedValue = (array)$poppedValue;
2267
+        $poppedValue = (array) $poppedValue;
2268 2268
       }
2269 2269
 
2270 2270
       $this->array = static::create($poppedValue)->array;
2271 2271
     } else {
2272
-      $number = (int)$number;
2272
+      $number = (int) $number;
2273 2273
       $this->array = $this->rest(-$number)->array;
2274 2274
     }
2275 2275
 
@@ -2608,7 +2608,7 @@  discard block
 block discarded – undo
2608 2608
       } elseif (\is_array($item)) {
2609 2609
         $result[$key] = self::create($item)->prependToEachKey($suffix)->toArray();
2610 2610
       } else {
2611
-        $result[$key . $suffix] = $item;
2611
+        $result[$key.$suffix] = $item;
2612 2612
       }
2613 2613
 
2614 2614
     }
@@ -2634,7 +2634,7 @@  discard block
 block discarded – undo
2634 2634
       } elseif (\is_object($item)) {
2635 2635
         $result[$key] = $item;
2636 2636
       } else {
2637
-        $result[$key] = $item . $suffix;
2637
+        $result[$key] = $item.$suffix;
2638 2638
       }
2639 2639
     }
2640 2640
 
@@ -2710,7 +2710,7 @@  discard block
 block discarded – undo
2710 2710
    */
2711 2711
   public function randomKeys($number)
2712 2712
   {
2713
-    $number = (int)$number;
2713
+    $number = (int) $number;
2714 2714
     $count = $this->count();
2715 2715
 
2716 2716
     if ($number === 0 || $number > $count) {
@@ -2723,7 +2723,7 @@  discard block
 block discarded – undo
2723 2723
       );
2724 2724
     }
2725 2725
 
2726
-    $result = (array)\array_rand($this->array, $number);
2726
+    $result = (array) \array_rand($this->array, $number);
2727 2727
 
2728 2728
     return static::create($result);
2729 2729
   }
@@ -2778,7 +2778,7 @@  discard block
 block discarded – undo
2778 2778
    */
2779 2779
   public function randomValues($number)
2780 2780
   {
2781
-    $number = (int)$number;
2781
+    $number = (int) $number;
2782 2782
 
2783 2783
     return $this->randomMutable($number);
2784 2784
   }
@@ -2822,7 +2822,7 @@  discard block
 block discarded – undo
2822 2822
     if ($result === null) {
2823 2823
       $this->array = array();
2824 2824
     } else {
2825
-      $this->array = (array)$result;
2825
+      $this->array = (array) $result;
2826 2826
     }
2827 2827
 
2828 2828
     return static::create($this->array);
@@ -2948,7 +2948,7 @@  discard block
 block discarded – undo
2948 2948
       return new static();
2949 2949
     }
2950 2950
 
2951
-    return static::create(\array_fill(0, (int)$times, $this->array));
2951
+    return static::create(\array_fill(0, (int) $times, $this->array));
2952 2952
   }
2953 2953
 
2954 2954
   /**
@@ -3041,7 +3041,7 @@  discard block
 block discarded – undo
3041 3041
   public function replaceValues($search, $replacement = '')
3042 3042
   {
3043 3043
     $array = $this->each(
3044
-        function ($value) use ($search, $replacement) {
3044
+        function($value) use ($search, $replacement) {
3045 3045
           return UTF8::str_replace($search, $replacement, $value);
3046 3046
         }
3047 3047
     );
@@ -3122,8 +3122,8 @@  discard block
 block discarded – undo
3122 3122
     }
3123 3123
 
3124 3124
     // php cast "bool"-index into "int"-index
3125
-    if ((bool)$index === $index) {
3126
-      $index = (int)$index;
3125
+    if ((bool) $index === $index) {
3126
+      $index = (int) $index;
3127 3127
     }
3128 3128
 
3129 3129
     if (\array_key_exists($index, $this->array) === true) {
@@ -3381,7 +3381,7 @@  discard block
 block discarded – undo
3381 3381
    */
3382 3382
   public function sorter($sorter = null, $direction = SORT_ASC, $strategy = SORT_REGULAR)
3383 3383
   {
3384
-    $array = (array)$this->array;
3384
+    $array = (array) $this->array;
3385 3385
     $direction = $this->getDirection($direction);
3386 3386
 
3387 3387
     // Transform all values into their results.
@@ -3390,7 +3390,7 @@  discard block
 block discarded – undo
3390 3390
 
3391 3391
       $that = $this;
3392 3392
       $results = $arrayy->each(
3393
-          function ($value) use ($sorter, $that) {
3393
+          function($value) use ($sorter, $that) {
3394 3394
             return \is_callable($sorter) ? $sorter($value) : $that->get($sorter, null, $value);
3395 3395
           }
3396 3396
       );
@@ -3487,8 +3487,8 @@  discard block
 block discarded – undo
3487 3487
     if ($arrayCount === 0) {
3488 3488
       $result = array();
3489 3489
     } else {
3490
-      $numberOfPieces = (int)$numberOfPieces;
3491
-      $splitSize = (int)\ceil($arrayCount / $numberOfPieces);
3490
+      $numberOfPieces = (int) $numberOfPieces;
3491
+      $splitSize = (int) \ceil($arrayCount / $numberOfPieces);
3492 3492
       $result = \array_chunk($this->array, $splitSize, $keepKeys);
3493 3493
     }
3494 3494
 
@@ -3503,12 +3503,12 @@  discard block
 block discarded – undo
3503 3503
   public function stripEmpty()
3504 3504
   {
3505 3505
     return $this->filter(
3506
-        function ($item) {
3506
+        function($item) {
3507 3507
           if ($item === null) {
3508 3508
             return false;
3509 3509
           }
3510 3510
 
3511
-          return (bool)\trim((string)$item);
3511
+          return (bool) \trim((string) $item);
3512 3512
         }
3513 3513
     );
3514 3514
   }
@@ -3576,7 +3576,7 @@  discard block
 block discarded – undo
3576 3576
 
3577 3577
     $this->array = \array_reduce(
3578 3578
         $this->array,
3579
-        function ($resultArray, $value) {
3579
+        function($resultArray, $value) {
3580 3580
           if (!in_array($value, $resultArray, true)) {
3581 3581
             $resultArray[] = $value;
3582 3582
           }
@@ -3589,7 +3589,7 @@  discard block
 block discarded – undo
3589 3589
     if ($this->array === null) {
3590 3590
       $this->array = array();
3591 3591
     } else {
3592
-      $this->array = (array)$this->array;
3592
+      $this->array = (array) $this->array;
3593 3593
     }
3594 3594
 
3595 3595
     return $this;
@@ -3609,7 +3609,7 @@  discard block
 block discarded – undo
3609 3609
 
3610 3610
     $this->array = \array_reduce(
3611 3611
         \array_keys($array),
3612
-        function ($resultArray, $key) use ($array) {
3612
+        function($resultArray, $key) use ($array) {
3613 3613
           if (!in_array($array[$key], $resultArray, true)) {
3614 3614
             $resultArray[$key] = $array[$key];
3615 3615
           }
@@ -3622,7 +3622,7 @@  discard block
 block discarded – undo
3622 3622
     if ($this->array === null) {
3623 3623
       $this->array = array();
3624 3624
     } else {
3625
-      $this->array = (array)$this->array;
3625
+      $this->array = (array) $this->array;
3626 3626
     }
3627 3627
 
3628 3628
     return $this;
@@ -3662,7 +3662,7 @@  discard block
 block discarded – undo
3662 3662
    */
3663 3663
   public function values()
3664 3664
   {
3665
-    return static::create(\array_values((array)$this->array));
3665
+    return static::create(\array_values((array) $this->array));
3666 3666
   }
3667 3667
 
3668 3668
   /**
Please login to merge, or discard this patch.