Completed
Push — master ( 24f92d...8dbc4c )
by Lars
02:45
created
src/Arrayy.php 1 patch
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
       &&
86 86
       \count(\array_diff_key($this->properties, $array)) > 0
87 87
     ) {
88
-      throw new \InvalidArgumentException('Property mismatch - input: ' . print_r(array_keys($array), true) . ' | expected: ' . print_r(array_keys($this->properties), true));
88
+      throw new \InvalidArgumentException('Property mismatch - input: '.print_r(array_keys($array), true).' | expected: '.print_r(array_keys($this->properties), true));
89 89
     }
90 90
 
91 91
     foreach ($array as $key => $value) {
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
       return $this->array[$key] ?? false;
127 127
     }
128 128
 
129
-    return (array)$this->array;
129
+    return (array) $this->array;
130 130
   }
131 131
 
132 132
   /**
@@ -370,8 +370,8 @@  discard block
 block discarded – undo
370 370
     }
371 371
 
372 372
     // php cast "bool"-index into "int"-index
373
-    if ((bool)$offset === $offset) {
374
-      $offset = (int)$offset;
373
+    if ((bool) $offset === $offset) {
374
+      $offset = (int) $offset;
375 375
     }
376 376
 
377 377
     $tmpReturn = \array_key_exists($offset, $this->array);
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
       (
383 383
         $tmpReturn === false
384 384
         &&
385
-        \strpos((string)$offset, $this->pathSeparator) === false
385
+        \strpos((string) $offset, $this->pathSeparator) === false
386 386
       )
387 387
     ) {
388 388
       return $tmpReturn;
@@ -390,16 +390,16 @@  discard block
 block discarded – undo
390 390
 
391 391
     $offsetExists = false;
392 392
 
393
-    if (\strpos((string)$offset, $this->pathSeparator) !== false) {
393
+    if (\strpos((string) $offset, $this->pathSeparator) !== false) {
394 394
 
395 395
       $offsetExists = false;
396
-      $explodedPath = \explode($this->pathSeparator, (string)$offset);
396
+      $explodedPath = \explode($this->pathSeparator, (string) $offset);
397 397
       $lastOffset = \array_pop($explodedPath);
398 398
       $containerPath = \implode($this->pathSeparator, $explodedPath);
399 399
 
400 400
       $this->callAtPath(
401 401
         $containerPath,
402
-        function ($container) use ($lastOffset, &$offsetExists) {
402
+        function($container) use ($lastOffset, &$offsetExists) {
403 403
           $offsetExists = \array_key_exists($lastOffset, $container);
404 404
         }
405 405
       );
@@ -452,14 +452,14 @@  discard block
 block discarded – undo
452 452
       return;
453 453
     }
454 454
 
455
-    if (\strpos((string)$offset, $this->pathSeparator) !== false) {
455
+    if (\strpos((string) $offset, $this->pathSeparator) !== false) {
456 456
 
457
-      $path = \explode($this->pathSeparator, (string)$offset);
457
+      $path = \explode($this->pathSeparator, (string) $offset);
458 458
       $pathToUnset = \array_pop($path);
459 459
 
460 460
       $this->callAtPath(
461 461
         \implode($this->pathSeparator, $path),
462
-        function (&$offset) use ($pathToUnset) {
462
+        function(&$offset) use ($pathToUnset) {
463 463
           unset($offset[$pathToUnset]);
464 464
         }
465 465
       );
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
     }
497 497
 
498 498
     if (\strpos($class, '\\') === 0) {
499
-      $class = '\\' . $class;
499
+      $class = '\\'.$class;
500 500
       if (\class_exists($class)) {
501 501
         $this->iteratorClass = $class;
502 502
 
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
       }
505 505
     }
506 506
 
507
-    throw new \InvalidArgumentException('The iterator class does not exist: ' . $class);
507
+    throw new \InvalidArgumentException('The iterator class does not exist: '.$class);
508 508
   }
509 509
 
510 510
   /**
@@ -604,13 +604,13 @@  discard block
 block discarded – undo
604 604
 
605 605
     foreach ($this->getGenerator() as $key => $item) {
606 606
       if ($item instanceof self) {
607
-        $result[$prefix . $key] = $item->appendToEachKey($prefix);
607
+        $result[$prefix.$key] = $item->appendToEachKey($prefix);
608 608
       } elseif (\is_array($item)) {
609
-        $result[$prefix . $key] = self::create($item, $this->iteratorClass, false)
609
+        $result[$prefix.$key] = self::create($item, $this->iteratorClass, false)
610 610
                                       ->appendToEachKey($prefix)
611 611
                                       ->toArray();
612 612
       } else {
613
-        $result[$prefix . $key] = $item;
613
+        $result[$prefix.$key] = $item;
614 614
       }
615 615
     }
616 616
 
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
       } elseif (\is_object($item)) {
638 638
         $result[$key] = $item;
639 639
       } else {
640
-        $result[$key] = $prefix . $item;
640
+        $result[$key] = $prefix.$item;
641 641
       }
642 642
     }
643 643
 
@@ -827,10 +827,10 @@  discard block
 block discarded – undo
827 827
 
828 828
       if ($case === CASE_LOWER) {
829 829
         /** @noinspection PhpComposerExtensionStubsInspection */
830
-        $key = \mb_strtolower((string)$key);
830
+        $key = \mb_strtolower((string) $key);
831 831
       } else {
832 832
         /** @noinspection PhpComposerExtensionStubsInspection */
833
-        $key = \mb_strtoupper((string)$key);
833
+        $key = \mb_strtoupper((string) $key);
834 834
       }
835 835
 
836 836
       $return[$key] = $value;
@@ -884,8 +884,8 @@  discard block
 block discarded – undo
884 884
   public function clean()
885 885
   {
886 886
     return $this->filter(
887
-      function ($value) {
888
-        return (bool)$value;
887
+      function($value) {
888
+        return (bool) $value;
889 889
       }
890 890
     );
891 891
   }
@@ -933,11 +933,11 @@  discard block
 block discarded – undo
933 933
     if ($recursive === true) {
934 934
       /** @noinspection PhpComposerExtensionStubsInspection */
935 935
       return $this->in_array_recursive(
936
-        \mb_strtoupper((string)$value),
936
+        \mb_strtoupper((string) $value),
937 937
         $this->walk(
938
-          function (&$val) {
938
+          function(&$val) {
939 939
             /** @noinspection PhpComposerExtensionStubsInspection */
940
-            $val = \mb_strtoupper((string)$val);
940
+            $val = \mb_strtoupper((string) $val);
941 941
           },
942 942
           true
943 943
         )->getArray(),
@@ -947,11 +947,11 @@  discard block
 block discarded – undo
947 947
 
948 948
     /** @noinspection PhpComposerExtensionStubsInspection */
949 949
     return \in_array(
950
-      \mb_strtoupper((string)$value),
950
+      \mb_strtoupper((string) $value),
951 951
       $this->walk(
952
-        function (&$val) {
952
+        function(&$val) {
953 953
           /** @noinspection PhpComposerExtensionStubsInspection */
954
-          $val = \mb_strtoupper((string)$val);
954
+          $val = \mb_strtoupper((string) $val);
955 955
         },
956 956
         false
957 957
       )->getArray(),
@@ -1199,7 +1199,7 @@  discard block
 block discarded – undo
1199 1199
     // trim all string in the array
1200 1200
     \array_walk(
1201 1201
       $array,
1202
-      function (&$val) {
1202
+      function(&$val) {
1203 1203
         /** @noinspection ReferenceMismatchInspection */
1204 1204
         if (\is_string($val)) {
1205 1205
           $val = \trim($val);
@@ -1444,7 +1444,7 @@  discard block
 block discarded – undo
1444 1444
     }
1445 1445
 
1446 1446
     if ($isObject && \method_exists($array, '__toArray')) {
1447
-      return (array)$array->__toArray();
1447
+      return (array) $array->__toArray();
1448 1448
     }
1449 1449
 
1450 1450
     /** @noinspection ReferenceMismatchInspection */
@@ -1453,7 +1453,7 @@  discard block
 block discarded – undo
1453 1453
       ||
1454 1454
       ($isObject && \method_exists($array, '__toString'))
1455 1455
     ) {
1456
-      return [(string)$array];
1456
+      return [(string) $array];
1457 1457
     }
1458 1458
 
1459 1459
     throw new \InvalidArgumentException(
@@ -1557,54 +1557,54 @@  discard block
 block discarded – undo
1557 1557
     }
1558 1558
 
1559 1559
     $ops = [
1560
-      'eq'          => function ($item, $prop, $value) {
1560
+      'eq'          => function($item, $prop, $value) {
1561 1561
         return $item[$prop] === $value;
1562 1562
       },
1563
-      'gt'          => function ($item, $prop, $value) {
1563
+      'gt'          => function($item, $prop, $value) {
1564 1564
         return $item[$prop] > $value;
1565 1565
       },
1566
-      'ge'          => function ($item, $prop, $value) {
1566
+      'ge'          => function($item, $prop, $value) {
1567 1567
         return $item[$prop] >= $value;
1568 1568
       },
1569
-      'gte'         => function ($item, $prop, $value) {
1569
+      'gte'         => function($item, $prop, $value) {
1570 1570
         return $item[$prop] >= $value;
1571 1571
       },
1572
-      'lt'          => function ($item, $prop, $value) {
1572
+      'lt'          => function($item, $prop, $value) {
1573 1573
         return $item[$prop] < $value;
1574 1574
       },
1575
-      'le'          => function ($item, $prop, $value) {
1575
+      'le'          => function($item, $prop, $value) {
1576 1576
         return $item[$prop] <= $value;
1577 1577
       },
1578
-      'lte'         => function ($item, $prop, $value) {
1578
+      'lte'         => function($item, $prop, $value) {
1579 1579
         return $item[$prop] <= $value;
1580 1580
       },
1581
-      'ne'          => function ($item, $prop, $value) {
1581
+      'ne'          => function($item, $prop, $value) {
1582 1582
         return $item[$prop] !== $value;
1583 1583
       },
1584
-      'contains'    => function ($item, $prop, $value) {
1585
-        return \in_array($item[$prop], (array)$value, true);
1584
+      'contains'    => function($item, $prop, $value) {
1585
+        return \in_array($item[$prop], (array) $value, true);
1586 1586
       },
1587
-      'notContains' => function ($item, $prop, $value) {
1588
-        return !\in_array($item[$prop], (array)$value, true);
1587
+      'notContains' => function($item, $prop, $value) {
1588
+        return !\in_array($item[$prop], (array) $value, true);
1589 1589
       },
1590
-      'newer'       => function ($item, $prop, $value) {
1590
+      'newer'       => function($item, $prop, $value) {
1591 1591
         return \strtotime($item[$prop]) > \strtotime($value);
1592 1592
       },
1593
-      'older'       => function ($item, $prop, $value) {
1593
+      'older'       => function($item, $prop, $value) {
1594 1594
         return \strtotime($item[$prop]) < \strtotime($value);
1595 1595
       },
1596 1596
     ];
1597 1597
 
1598 1598
     $result = \array_values(
1599 1599
       \array_filter(
1600
-        (array)$this->array,
1601
-        function ($item) use (
1600
+        (array) $this->array,
1601
+        function($item) use (
1602 1602
           $property,
1603 1603
           $value,
1604 1604
           $ops,
1605 1605
           $comparisonOp
1606 1606
         ) {
1607
-          $item = (array)$item;
1607
+          $item = (array) $item;
1608 1608
           $itemArrayy = new Arrayy($item);
1609 1609
           $item[$property] = $itemArrayy->get($property, []);
1610 1610
 
@@ -1673,9 +1673,9 @@  discard block
 block discarded – undo
1673 1673
   {
1674 1674
     if ($number === null) {
1675 1675
       $arrayTmp = $this->array;
1676
-      $array = (array)\array_shift($arrayTmp);
1676
+      $array = (array) \array_shift($arrayTmp);
1677 1677
     } else {
1678
-      $number = (int)$number;
1678
+      $number = (int) $number;
1679 1679
       $arrayTmp = $this->array;
1680 1680
       $array = \array_splice($arrayTmp, 0, $number, true);
1681 1681
     }
@@ -1693,9 +1693,9 @@  discard block
 block discarded – undo
1693 1693
   public function firstsMutable(int $number = null)
1694 1694
   {
1695 1695
     if ($number === null) {
1696
-      $this->array = (array)\array_shift($this->array);
1696
+      $this->array = (array) \array_shift($this->array);
1697 1697
     } else {
1698
-      $number = (int)$number;
1698
+      $number = (int) $number;
1699 1699
       $this->array = \array_splice($this->array, 0, $number, true);
1700 1700
     }
1701 1701
 
@@ -1739,8 +1739,8 @@  discard block
 block discarded – undo
1739 1739
     }
1740 1740
 
1741 1741
     // php cast "bool"-index into "int"-index
1742
-    if ((bool)$key === $key) {
1743
-      $key = (int)$key;
1742
+    if ((bool) $key === $key) {
1743
+      $key = (int) $key;
1744 1744
     }
1745 1745
 
1746 1746
     if (\array_key_exists($key, $usedArray) === true) {
@@ -1752,7 +1752,7 @@  discard block
 block discarded – undo
1752 1752
     }
1753 1753
 
1754 1754
     // Crawl through array, get key according to object or not
1755
-    foreach (\explode($this->pathSeparator, (string)$key) as $segment) {
1755
+    foreach (\explode($this->pathSeparator, (string) $key) as $segment) {
1756 1756
       if (!isset($usedArray[$segment])) {
1757 1757
         return $fallback instanceof \Closure ? $fallback() : $fallback;
1758 1758
       }
@@ -1866,7 +1866,7 @@  discard block
 block discarded – undo
1866 1866
   protected function getPublicProperties(): array
1867 1867
   {
1868 1868
     static $PROPERTY_CACHE = [];
1869
-    $cacheKey = 'Class::' . static::class;
1869
+    $cacheKey = 'Class::'.static::class;
1870 1870
 
1871 1871
     if (isset($PROPERTY_CACHE[$cacheKey])) {
1872 1872
       return $PROPERTY_CACHE[$cacheKey];
@@ -2063,7 +2063,7 @@  discard block
 block discarded – undo
2063 2063
       );
2064 2064
     }
2065 2065
 
2066
-    return (string)$pieces;
2066
+    return (string) $pieces;
2067 2067
   }
2068 2068
 
2069 2069
   /**
@@ -2197,7 +2197,7 @@  discard block
 block discarded – undo
2197 2197
    */
2198 2198
   protected function internalRemove($key): bool
2199 2199
   {
2200
-    $path = \explode($this->pathSeparator, (string)$key);
2200
+    $path = \explode($this->pathSeparator, (string) $key);
2201 2201
 
2202 2202
     // Crawl though the keys
2203 2203
     while (\count($path, COUNT_NORMAL) > 1) {
@@ -2229,7 +2229,7 @@  discard block
 block discarded – undo
2229 2229
   {
2230 2230
     if ($this->checkPropertyTypes === true) {
2231 2231
       if (isset($this->properties[$key]) === false) {
2232
-        throw new \InvalidArgumentException('The key ' . $key . ' does not exists as @property in the class (' . \get_class($this) . ').');
2232
+        throw new \InvalidArgumentException('The key '.$key.' does not exists as @property in the class ('.\get_class($this).').');
2233 2233
       }
2234 2234
 
2235 2235
       $this->properties[$key]->checkType($value);
@@ -2240,14 +2240,14 @@  discard block
 block discarded – undo
2240 2240
     }
2241 2241
 
2242 2242
     // init
2243
-    $array =& $this->array;
2244
-    $path = \explode($this->pathSeparator, (string)$key);
2243
+    $array = & $this->array;
2244
+    $path = \explode($this->pathSeparator, (string) $key);
2245 2245
 
2246 2246
     // Crawl through the keys
2247 2247
     while (\count($path, COUNT_NORMAL) > 1) {
2248 2248
       $key = \array_shift($path);
2249 2249
 
2250
-      $array =& $array[$key];
2250
+      $array = & $array[$key];
2251 2251
     }
2252 2252
 
2253 2253
     $array[\array_shift($path)] = $value;
@@ -2510,12 +2510,12 @@  discard block
 block discarded – undo
2510 2510
       if ($poppedValue === null) {
2511 2511
         $poppedValue = [$poppedValue];
2512 2512
       } else {
2513
-        $poppedValue = (array)$poppedValue;
2513
+        $poppedValue = (array) $poppedValue;
2514 2514
       }
2515 2515
 
2516 2516
       $arrayy = static::create($poppedValue, $this->iteratorClass, false);
2517 2517
     } else {
2518
-      $number = (int)$number;
2518
+      $number = (int) $number;
2519 2519
       $arrayy = $this->rest(-$number);
2520 2520
     }
2521 2521
 
@@ -2541,12 +2541,12 @@  discard block
 block discarded – undo
2541 2541
       if ($poppedValue === null) {
2542 2542
         $poppedValue = [$poppedValue];
2543 2543
       } else {
2544
-        $poppedValue = (array)$poppedValue;
2544
+        $poppedValue = (array) $poppedValue;
2545 2545
       }
2546 2546
 
2547 2547
       $this->array = static::create($poppedValue, $this->iteratorClass, false)->array;
2548 2548
     } else {
2549
-      $number = (int)$number;
2549
+      $number = (int) $number;
2550 2550
       $this->array = $this->rest(-$number)->array;
2551 2551
     }
2552 2552
 
@@ -2897,7 +2897,7 @@  discard block
 block discarded – undo
2897 2897
       } elseif (\is_array($item)) {
2898 2898
         $result[$key] = self::create($item, $this->iteratorClass, false)->prependToEachKey($suffix)->toArray();
2899 2899
       } else {
2900
-        $result[$key . $suffix] = $item;
2900
+        $result[$key.$suffix] = $item;
2901 2901
       }
2902 2902
 
2903 2903
     }
@@ -2927,7 +2927,7 @@  discard block
 block discarded – undo
2927 2927
       } elseif (\is_object($item)) {
2928 2928
         $result[$key] = $item;
2929 2929
       } else {
2930
-        $result[$key] = $item . $suffix;
2930
+        $result[$key] = $item.$suffix;
2931 2931
       }
2932 2932
     }
2933 2933
 
@@ -3017,7 +3017,7 @@  discard block
 block discarded – undo
3017 3017
       );
3018 3018
     }
3019 3019
 
3020
-    $result = (array)\array_rand($this->array, $number);
3020
+    $result = (array) \array_rand($this->array, $number);
3021 3021
 
3022 3022
     return static::create($result, $this->iteratorClass, false);
3023 3023
   }
@@ -3118,7 +3118,7 @@  discard block
 block discarded – undo
3118 3118
     if ($result === null) {
3119 3119
       $this->array = [];
3120 3120
     } else {
3121
-      $this->array = (array)$result;
3121
+      $this->array = (array) $result;
3122 3122
     }
3123 3123
 
3124 3124
     return static::create($this->array, $this->iteratorClass, false);
@@ -3245,7 +3245,7 @@  discard block
 block discarded – undo
3245 3245
     }
3246 3246
 
3247 3247
     return static::create(
3248
-      \array_fill(0, (int)$times, $this->array),
3248
+      \array_fill(0, (int) $times, $this->array),
3249 3249
       $this->iteratorClass,
3250 3250
       false
3251 3251
     );
@@ -3345,7 +3345,7 @@  discard block
 block discarded – undo
3345 3345
   public function replaceValues($search, $replacement = '')
3346 3346
   {
3347 3347
     $array = $this->each(
3348
-      function ($value) use ($search, $replacement) {
3348
+      function($value) use ($search, $replacement) {
3349 3349
         return \str_replace($search, $replacement, $value);
3350 3350
       }
3351 3351
     );
@@ -3430,8 +3430,8 @@  discard block
 block discarded – undo
3430 3430
     }
3431 3431
 
3432 3432
     // php cast "bool"-index into "int"-index
3433
-    if ((bool)$index === $index) {
3434
-      $index = (int)$index;
3433
+    if ((bool) $index === $index) {
3434
+      $index = (int) $index;
3435 3435
     }
3436 3436
 
3437 3437
     if (\array_key_exists($index, $this->array) === true) {
@@ -3674,7 +3674,7 @@  discard block
 block discarded – undo
3674 3674
    */
3675 3675
   public function sorter($sorter = null, $direction = SORT_ASC, int $strategy = SORT_REGULAR)
3676 3676
   {
3677
-    $array = (array)$this->array;
3677
+    $array = (array) $this->array;
3678 3678
     $direction = $this->getDirection($direction);
3679 3679
 
3680 3680
     // Transform all values into their results.
@@ -3683,7 +3683,7 @@  discard block
 block discarded – undo
3683 3683
 
3684 3684
       $that = $this;
3685 3685
       $results = $arrayy->each(
3686
-        function ($value) use ($sorter, $that) {
3686
+        function($value) use ($sorter, $that) {
3687 3687
           return \is_callable($sorter) ? $sorter($value) : $that->get($sorter, null, $value);
3688 3688
         }
3689 3689
       );
@@ -3781,7 +3781,7 @@  discard block
 block discarded – undo
3781 3781
     if ($arrayCount === 0) {
3782 3782
       $result = [];
3783 3783
     } else {
3784
-      $splitSize = (int)\ceil($arrayCount / $numberOfPieces);
3784
+      $splitSize = (int) \ceil($arrayCount / $numberOfPieces);
3785 3785
       $result = \array_chunk($this->array, $splitSize, $keepKeys);
3786 3786
     }
3787 3787
 
@@ -3796,12 +3796,12 @@  discard block
 block discarded – undo
3796 3796
   public function stripEmpty()
3797 3797
   {
3798 3798
     return $this->filter(
3799
-      function ($item) {
3799
+      function($item) {
3800 3800
         if ($item === null) {
3801 3801
           return false;
3802 3802
         }
3803 3803
 
3804
-        return (bool)\trim((string)$item);
3804
+        return (bool) \trim((string) $item);
3805 3805
       }
3806 3806
     );
3807 3807
   }
@@ -3870,7 +3870,7 @@  discard block
 block discarded – undo
3870 3870
 
3871 3871
     $this->array = \array_reduce(
3872 3872
       $this->array,
3873
-      function ($resultArray, $value) {
3873
+      function($resultArray, $value) {
3874 3874
         if (!\in_array($value, $resultArray, true)) {
3875 3875
           $resultArray[] = $value;
3876 3876
         }
@@ -3883,7 +3883,7 @@  discard block
 block discarded – undo
3883 3883
     if ($this->array === null) {
3884 3884
       $this->array = [];
3885 3885
     } else {
3886
-      $this->array = (array)$this->array;
3886
+      $this->array = (array) $this->array;
3887 3887
     }
3888 3888
 
3889 3889
     return $this;
@@ -3903,7 +3903,7 @@  discard block
 block discarded – undo
3903 3903
 
3904 3904
     $this->array = \array_reduce(
3905 3905
       \array_keys($array),
3906
-      function ($resultArray, $key) use ($array) {
3906
+      function($resultArray, $key) use ($array) {
3907 3907
         if (!\in_array($array[$key], $resultArray, true)) {
3908 3908
           $resultArray[$key] = $array[$key];
3909 3909
         }
@@ -3916,7 +3916,7 @@  discard block
 block discarded – undo
3916 3916
     if ($this->array === null) {
3917 3917
       $this->array = [];
3918 3918
     } else {
3919
-      $this->array = (array)$this->array;
3919
+      $this->array = (array) $this->array;
3920 3920
     }
3921 3921
 
3922 3922
     return $this;
@@ -3957,7 +3957,7 @@  discard block
 block discarded – undo
3957 3957
   public function values()
3958 3958
   {
3959 3959
     return static::create(
3960
-      \array_values((array)$this->array),
3960
+      \array_values((array) $this->array),
3961 3961
       $this->iteratorClass,
3962 3962
       false
3963 3963
     );
Please login to merge, or discard this patch.