@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare(strict_types=1); |
|
3 | +declare(strict_types = 1); |
|
4 | 4 | |
5 | 5 | namespace Arrayy; |
6 | 6 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - return (array)$this->array; |
|
77 | + return (array) $this->array; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | ( |
190 | 190 | $tmpReturn === false |
191 | 191 | && |
192 | - strpos((string)$offset, $this->pathSeparator) === false |
|
192 | + strpos((string) $offset, $this->pathSeparator) === false |
|
193 | 193 | ) |
194 | 194 | ) { |
195 | 195 | |
@@ -199,16 +199,16 @@ discard block |
||
199 | 199 | |
200 | 200 | $offsetExists = false; |
201 | 201 | |
202 | - if (strpos((string)$offset, $this->pathSeparator) !== false) { |
|
202 | + if (strpos((string) $offset, $this->pathSeparator) !== false) { |
|
203 | 203 | |
204 | 204 | $offsetExists = false; |
205 | - $explodedPath = explode($this->pathSeparator, (string)$offset); |
|
205 | + $explodedPath = explode($this->pathSeparator, (string) $offset); |
|
206 | 206 | $lastOffset = array_pop($explodedPath); |
207 | 207 | $containerPath = implode($this->pathSeparator, $explodedPath); |
208 | 208 | |
209 | 209 | $this->callAtPath( |
210 | 210 | $containerPath, |
211 | - function ($container) use ($lastOffset, &$offsetExists) { |
|
211 | + function($container) use ($lastOffset, &$offsetExists) { |
|
212 | 212 | $offsetExists = isset($container[$lastOffset]); |
213 | 213 | } |
214 | 214 | ); |
@@ -258,14 +258,14 @@ discard block |
||
258 | 258 | return; |
259 | 259 | } |
260 | 260 | |
261 | - if (strpos((string)$offset, $this->pathSeparator) !== false) { |
|
261 | + if (strpos((string) $offset, $this->pathSeparator) !== false) { |
|
262 | 262 | |
263 | - $path = explode($this->pathSeparator, (string)$offset); |
|
263 | + $path = explode($this->pathSeparator, (string) $offset); |
|
264 | 264 | $pathToUnset = array_pop($path); |
265 | 265 | |
266 | 266 | $this->callAtPath( |
267 | 267 | implode($this->pathSeparator, $path), |
268 | - function (&$offset) use (&$pathToUnset) { |
|
268 | + function(&$offset) use (&$pathToUnset) { |
|
269 | 269 | unset($offset[$pathToUnset]); |
270 | 270 | } |
271 | 271 | ); |
@@ -405,8 +405,8 @@ discard block |
||
405 | 405 | public function clean() |
406 | 406 | { |
407 | 407 | return $this->filter( |
408 | - function ($value) { |
|
409 | - return (bool)$value; |
|
408 | + function($value) { |
|
409 | + return (bool) $value; |
|
410 | 410 | } |
411 | 411 | ); |
412 | 412 | } |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | // trim all string in the array |
593 | 593 | array_walk( |
594 | 594 | $array, |
595 | - function (&$val) { |
|
595 | + function(&$val) { |
|
596 | 596 | /** @noinspection ReferenceMismatchInspection */ |
597 | 597 | if (is_string($val)) { |
598 | 598 | $val = trim($val); |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | } |
810 | 810 | |
811 | 811 | if (is_object($array) && method_exists($array, '__toArray')) { |
812 | - return (array)$array->__toArray(); |
|
812 | + return (array) $array->__toArray(); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | /** @noinspection ReferenceMismatchInspection */ |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | || |
819 | 819 | (is_object($array) && method_exists($array, '__toString')) |
820 | 820 | ) { |
821 | - return (array)$array; |
|
821 | + return (array) $array; |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | throw new \InvalidArgumentException( |
@@ -871,54 +871,54 @@ discard block |
||
871 | 871 | } |
872 | 872 | |
873 | 873 | $ops = array( |
874 | - 'eq' => function ($item, $prop, $value) { |
|
874 | + 'eq' => function($item, $prop, $value) { |
|
875 | 875 | return $item[$prop] === $value; |
876 | 876 | }, |
877 | - 'gt' => function ($item, $prop, $value) { |
|
877 | + 'gt' => function($item, $prop, $value) { |
|
878 | 878 | return $item[$prop] > $value; |
879 | 879 | }, |
880 | - 'ge' => function ($item, $prop, $value) { |
|
880 | + 'ge' => function($item, $prop, $value) { |
|
881 | 881 | return $item[$prop] >= $value; |
882 | 882 | }, |
883 | - 'gte' => function ($item, $prop, $value) { |
|
883 | + 'gte' => function($item, $prop, $value) { |
|
884 | 884 | return $item[$prop] >= $value; |
885 | 885 | }, |
886 | - 'lt' => function ($item, $prop, $value) { |
|
886 | + 'lt' => function($item, $prop, $value) { |
|
887 | 887 | return $item[$prop] < $value; |
888 | 888 | }, |
889 | - 'le' => function ($item, $prop, $value) { |
|
889 | + 'le' => function($item, $prop, $value) { |
|
890 | 890 | return $item[$prop] <= $value; |
891 | 891 | }, |
892 | - 'lte' => function ($item, $prop, $value) { |
|
892 | + 'lte' => function($item, $prop, $value) { |
|
893 | 893 | return $item[$prop] <= $value; |
894 | 894 | }, |
895 | - 'ne' => function ($item, $prop, $value) { |
|
895 | + 'ne' => function($item, $prop, $value) { |
|
896 | 896 | return $item[$prop] !== $value; |
897 | 897 | }, |
898 | - 'contains' => function ($item, $prop, $value) { |
|
899 | - return in_array($item[$prop], (array)$value, true); |
|
898 | + 'contains' => function($item, $prop, $value) { |
|
899 | + return in_array($item[$prop], (array) $value, true); |
|
900 | 900 | }, |
901 | - 'notContains' => function ($item, $prop, $value) { |
|
902 | - return !in_array($item[$prop], (array)$value, true); |
|
901 | + 'notContains' => function($item, $prop, $value) { |
|
902 | + return !in_array($item[$prop], (array) $value, true); |
|
903 | 903 | }, |
904 | - 'newer' => function ($item, $prop, $value) { |
|
904 | + 'newer' => function($item, $prop, $value) { |
|
905 | 905 | return strtotime($item[$prop]) > strtotime($value); |
906 | 906 | }, |
907 | - 'older' => function ($item, $prop, $value) { |
|
907 | + 'older' => function($item, $prop, $value) { |
|
908 | 908 | return strtotime($item[$prop]) < strtotime($value); |
909 | 909 | }, |
910 | 910 | ); |
911 | 911 | |
912 | 912 | $result = array_values( |
913 | 913 | array_filter( |
914 | - (array)$this->array, |
|
915 | - function ($item) use ( |
|
914 | + (array) $this->array, |
|
915 | + function($item) use ( |
|
916 | 916 | $property, |
917 | 917 | $value, |
918 | 918 | $ops, |
919 | 919 | $comparisonOp |
920 | 920 | ) { |
921 | - $item = (array)$item; |
|
921 | + $item = (array) $item; |
|
922 | 922 | $itemArrayy = new Arrayy($item); |
923 | 923 | $item[$property] = $itemArrayy->get($property, array()); |
924 | 924 | |
@@ -991,9 +991,9 @@ discard block |
||
991 | 991 | { |
992 | 992 | if ($number === null) { |
993 | 993 | $arrayTmp = $this->array; |
994 | - $array = (array)array_shift($arrayTmp); |
|
994 | + $array = (array) array_shift($arrayTmp); |
|
995 | 995 | } else { |
996 | - $number = (int)$number; |
|
996 | + $number = (int) $number; |
|
997 | 997 | $arrayTmp = $this->array; |
998 | 998 | $array = array_splice($arrayTmp, 0, $number, true); |
999 | 999 | } |
@@ -1011,9 +1011,9 @@ discard block |
||
1011 | 1011 | public function firstsMutable($number = null) |
1012 | 1012 | { |
1013 | 1013 | if ($number === null) { |
1014 | - $this->array = (array)array_shift($this->array); |
|
1014 | + $this->array = (array) array_shift($this->array); |
|
1015 | 1015 | } else { |
1016 | - $number = (int)$number; |
|
1016 | + $number = (int) $number; |
|
1017 | 1017 | $this->array = array_splice($this->array, 0, $number, true); |
1018 | 1018 | } |
1019 | 1019 | |
@@ -1066,7 +1066,7 @@ discard block |
||
1066 | 1066 | } |
1067 | 1067 | |
1068 | 1068 | // Crawl through array, get key according to object or not |
1069 | - foreach (explode($this->pathSeparator, (string)$key) as $segment) { |
|
1069 | + foreach (explode($this->pathSeparator, (string) $key) as $segment) { |
|
1070 | 1070 | if (!isset($usedArray[$segment])) { |
1071 | 1071 | return $default instanceof \Closure ? $default() : $default; |
1072 | 1072 | } |
@@ -1238,7 +1238,7 @@ discard block |
||
1238 | 1238 | */ |
1239 | 1239 | public function group($grouper, $saveKeys = false) |
1240 | 1240 | { |
1241 | - $array = (array)$this->array; |
|
1241 | + $array = (array) $this->array; |
|
1242 | 1242 | $result = array(); |
1243 | 1243 | |
1244 | 1244 | // Iterate over values, group by property/results from closure |
@@ -1281,7 +1281,7 @@ discard block |
||
1281 | 1281 | public function has($key) |
1282 | 1282 | { |
1283 | 1283 | // Generate unique string to use as marker. |
1284 | - $unFound = (string)uniqid('arrayy', true); |
|
1284 | + $unFound = (string) uniqid('arrayy', true); |
|
1285 | 1285 | |
1286 | 1286 | return $this->get($key, $unFound) !== $unFound; |
1287 | 1287 | } |
@@ -1359,7 +1359,7 @@ discard block |
||
1359 | 1359 | */ |
1360 | 1360 | protected function internalRemove($key) |
1361 | 1361 | { |
1362 | - $path = explode($this->pathSeparator, (string)$key); |
|
1362 | + $path = explode($this->pathSeparator, (string) $key); |
|
1363 | 1363 | |
1364 | 1364 | // Crawl though the keys |
1365 | 1365 | while (count($path) > 1) { |
@@ -1394,8 +1394,8 @@ discard block |
||
1394 | 1394 | } |
1395 | 1395 | |
1396 | 1396 | // init |
1397 | - $array =& $this->array; |
|
1398 | - $path = explode($this->pathSeparator, (string)$key); |
|
1397 | + $array = & $this->array; |
|
1398 | + $path = explode($this->pathSeparator, (string) $key); |
|
1399 | 1399 | |
1400 | 1400 | // Crawl through the keys |
1401 | 1401 | while (count($path) > 1) { |
@@ -1408,7 +1408,7 @@ discard block |
||
1408 | 1408 | $array[$key] = self::create(array()); |
1409 | 1409 | } |
1410 | 1410 | |
1411 | - $array =& $array[$key]; |
|
1411 | + $array = & $array[$key]; |
|
1412 | 1412 | } |
1413 | 1413 | |
1414 | 1414 | $array[array_shift($path)] = $value; |
@@ -1577,10 +1577,10 @@ discard block |
||
1577 | 1577 | public function lastsImmutable($number = null) |
1578 | 1578 | { |
1579 | 1579 | if ($number === null) { |
1580 | - $poppedValue = (array)$this->pop(); |
|
1580 | + $poppedValue = (array) $this->pop(); |
|
1581 | 1581 | $arrayy = static::create($poppedValue); |
1582 | 1582 | } else { |
1583 | - $number = (int)$number; |
|
1583 | + $number = (int) $number; |
|
1584 | 1584 | $arrayy = $this->rest(-$number); |
1585 | 1585 | } |
1586 | 1586 | |
@@ -1597,10 +1597,10 @@ discard block |
||
1597 | 1597 | public function lastsMutable($number = null) |
1598 | 1598 | { |
1599 | 1599 | if ($number === null) { |
1600 | - $poppedValue = (array)$this->pop(); |
|
1600 | + $poppedValue = (array) $this->pop(); |
|
1601 | 1601 | $this->array = static::create($poppedValue)->array; |
1602 | 1602 | } else { |
1603 | - $number = (int)$number; |
|
1603 | + $number = (int) $number; |
|
1604 | 1604 | $this->array = $this->rest(-$number)->array; |
1605 | 1605 | } |
1606 | 1606 | |
@@ -1882,7 +1882,7 @@ discard block |
||
1882 | 1882 | } |
1883 | 1883 | |
1884 | 1884 | if ($number === null) { |
1885 | - $arrayRandValue = (array)$this->array[array_rand($this->array)]; |
|
1885 | + $arrayRandValue = (array) $this->array[array_rand($this->array)]; |
|
1886 | 1886 | |
1887 | 1887 | return static::create($arrayRandValue); |
1888 | 1888 | } |
@@ -1923,7 +1923,7 @@ discard block |
||
1923 | 1923 | */ |
1924 | 1924 | public function randomKeys($number) |
1925 | 1925 | { |
1926 | - $number = (int)$number; |
|
1926 | + $number = (int) $number; |
|
1927 | 1927 | $count = $this->count(); |
1928 | 1928 | |
1929 | 1929 | if ($number === 0 || $number > $count) { |
@@ -1936,7 +1936,7 @@ discard block |
||
1936 | 1936 | ); |
1937 | 1937 | } |
1938 | 1938 | |
1939 | - $result = (array)array_rand($this->array, $number); |
|
1939 | + $result = (array) array_rand($this->array, $number); |
|
1940 | 1940 | |
1941 | 1941 | return static::create($result); |
1942 | 1942 | } |
@@ -1955,7 +1955,7 @@ discard block |
||
1955 | 1955 | } |
1956 | 1956 | |
1957 | 1957 | if ($number === null) { |
1958 | - $arrayRandValue = (array)$this->array[array_rand($this->array)]; |
|
1958 | + $arrayRandValue = (array) $this->array[array_rand($this->array)]; |
|
1959 | 1959 | $this->array = $arrayRandValue; |
1960 | 1960 | |
1961 | 1961 | return $this; |
@@ -1991,7 +1991,7 @@ discard block |
||
1991 | 1991 | */ |
1992 | 1992 | public function randomValues($number) |
1993 | 1993 | { |
1994 | - $number = (int)$number; |
|
1994 | + $number = (int) $number; |
|
1995 | 1995 | |
1996 | 1996 | return $this->randomMutable($number); |
1997 | 1997 | } |
@@ -2035,7 +2035,7 @@ discard block |
||
2035 | 2035 | if ($result === null) { |
2036 | 2036 | $this->array = array(); |
2037 | 2037 | } else { |
2038 | - $this->array = (array)$result; |
|
2038 | + $this->array = (array) $result; |
|
2039 | 2039 | } |
2040 | 2040 | |
2041 | 2041 | return static::create($this->array); |
@@ -2238,7 +2238,7 @@ discard block |
||
2238 | 2238 | public function replaceValues($search, $replacement = '') |
2239 | 2239 | { |
2240 | 2240 | $array = $this->each( |
2241 | - function ($value) use ($search, $replacement) { |
|
2241 | + function($value) use ($search, $replacement) { |
|
2242 | 2242 | return UTF8::str_replace($search, $replacement, $value); |
2243 | 2243 | } |
2244 | 2244 | ); |
@@ -2284,7 +2284,7 @@ discard block |
||
2284 | 2284 | array_splice($array, $indexToMove, 1); |
2285 | 2285 | $i = 0; |
2286 | 2286 | $output = array(); |
2287 | - foreach($array as $key => $item) { |
|
2287 | + foreach ($array as $key => $item) { |
|
2288 | 2288 | if ($i == $to) { |
2289 | 2289 | $output[$from] = $itemToMove; |
2290 | 2290 | } |
@@ -2504,7 +2504,7 @@ discard block |
||
2504 | 2504 | */ |
2505 | 2505 | public function sorter($sorter = null, $direction = SORT_ASC, $strategy = SORT_REGULAR) |
2506 | 2506 | { |
2507 | - $array = (array)$this->array; |
|
2507 | + $array = (array) $this->array; |
|
2508 | 2508 | $direction = $this->getDirection($direction); |
2509 | 2509 | |
2510 | 2510 | // Transform all values into their results. |
@@ -2513,7 +2513,7 @@ discard block |
||
2513 | 2513 | |
2514 | 2514 | $that = $this; |
2515 | 2515 | $results = $arrayy->each( |
2516 | - function ($value) use ($sorter, $that) { |
|
2516 | + function($value) use ($sorter, $that) { |
|
2517 | 2517 | return is_callable($sorter) ? $sorter($value) : $that->get($sorter, null, $value); |
2518 | 2518 | } |
2519 | 2519 | ); |
@@ -2601,8 +2601,8 @@ discard block |
||
2601 | 2601 | if ($arrayCount === 0) { |
2602 | 2602 | $result = array(); |
2603 | 2603 | } else { |
2604 | - $numberOfPieces = (int)$numberOfPieces; |
|
2605 | - $splitSize = (int)ceil($arrayCount / $numberOfPieces); |
|
2604 | + $numberOfPieces = (int) $numberOfPieces; |
|
2605 | + $splitSize = (int) ceil($arrayCount / $numberOfPieces); |
|
2606 | 2606 | $result = array_chunk($this->array, $splitSize, $keepKeys); |
2607 | 2607 | } |
2608 | 2608 | |
@@ -2617,12 +2617,12 @@ discard block |
||
2617 | 2617 | public function stripEmpty() |
2618 | 2618 | { |
2619 | 2619 | return $this->filter( |
2620 | - function ($item) { |
|
2620 | + function($item) { |
|
2621 | 2621 | if ($item === null) { |
2622 | 2622 | return false; |
2623 | 2623 | } |
2624 | 2624 | |
2625 | - return (bool)trim((string)$item); |
|
2625 | + return (bool) trim((string) $item); |
|
2626 | 2626 | } |
2627 | 2627 | ); |
2628 | 2628 | } |
@@ -2687,7 +2687,7 @@ discard block |
||
2687 | 2687 | { |
2688 | 2688 | $this->array = array_reduce( |
2689 | 2689 | $this->array, |
2690 | - function ($resultArray, $value) { |
|
2690 | + function($resultArray, $value) { |
|
2691 | 2691 | if (!in_array($value, $resultArray, true)) { |
2692 | 2692 | $resultArray[] = $value; |
2693 | 2693 | } |
@@ -2700,7 +2700,7 @@ discard block |
||
2700 | 2700 | if ($this->array === null) { |
2701 | 2701 | $this->array = array(); |
2702 | 2702 | } else { |
2703 | - $this->array = (array)$this->array; |
|
2703 | + $this->array = (array) $this->array; |
|
2704 | 2704 | } |
2705 | 2705 | |
2706 | 2706 | return $this; |
@@ -2728,7 +2728,7 @@ discard block |
||
2728 | 2728 | */ |
2729 | 2729 | public function values() |
2730 | 2730 | { |
2731 | - return static::create(array_values((array)$this->array)); |
|
2731 | + return static::create(array_values((array) $this->array)); |
|
2732 | 2732 | } |
2733 | 2733 | |
2734 | 2734 | /** |