@@ -2,10 +2,10 @@ |
||
2 | 2 | |
3 | 3 | namespace IlluminateAgnostic\Collection\Support\Traits; |
4 | 4 | |
5 | +use BadMethodCallException; |
|
5 | 6 | use Closure; |
6 | 7 | use ReflectionClass; |
7 | 8 | use ReflectionMethod; |
8 | -use BadMethodCallException; |
|
9 | 9 | |
10 | 10 | trait Macroable |
11 | 11 | { |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | ); |
46 | 46 | |
47 | 47 | foreach ($methods as $method) { |
48 | - if ($replace || ! static::hasMacro($method->name)) { |
|
48 | + if ($replace || !static::hasMacro($method->name)) { |
|
49 | 49 | $method->setAccessible(true); |
50 | 50 | static::macro($method->name, $method->invoke($mixin)); |
51 | 51 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public static function __callStatic($method, $parameters) |
76 | 76 | { |
77 | - if (! static::hasMacro($method)) { |
|
77 | + if (!static::hasMacro($method)) { |
|
78 | 78 | throw new BadMethodCallException(sprintf( |
79 | 79 | 'Method %s::%s does not exist.', static::class, $method |
80 | 80 | )); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function __call($method, $parameters) |
100 | 100 | { |
101 | - if (! static::hasMacro($method)) { |
|
101 | + if (!static::hasMacro($method)) { |
|
102 | 102 | throw new BadMethodCallException(sprintf( |
103 | 103 | 'Method %s::%s does not exist.', static::class, $method |
104 | 104 | )); |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | { |
57 | 57 | $languageSpecific = static::languageSpecificCharsArray($language); |
58 | 58 | |
59 | - if (! is_null($languageSpecific)) { |
|
59 | + if (!is_null($languageSpecific)) { |
|
60 | 60 | $value = str_replace($languageSpecific[0], $languageSpecific[1], $value); |
61 | 61 | } |
62 | 62 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | { |
250 | 250 | preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches); |
251 | 251 | |
252 | - if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) { |
|
252 | + if (!isset($matches[0]) || static::length($value) === static::length($matches[0])) { |
|
253 | 253 | return $value; |
254 | 254 | } |
255 | 255 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | return static::$snakeCache[$key][$delimiter]; |
468 | 468 | } |
469 | 469 | |
470 | - if (! ctype_lower($value)) { |
|
470 | + if (!ctype_lower($value)) { |
|
471 | 471 | $value = preg_replace('/\s+/u', '', ucwords($value)); |
472 | 472 | |
473 | 473 | $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value)); |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | { |
717 | 717 | static $languageSpecific; |
718 | 718 | |
719 | - if (! isset($languageSpecific)) { |
|
719 | + if (!isset($languageSpecific)) { |
|
720 | 720 | $languageSpecific = [ |
721 | 721 | 'bg' => [ |
722 | 722 | ['х', 'Х', 'щ', 'Щ', 'ъ', 'Ъ', 'ь', 'Ь'], |
@@ -727,7 +727,7 @@ discard block |
||
727 | 727 | ['ae', 'oe', 'aa', 'Ae', 'Oe', 'Aa'], |
728 | 728 | ], |
729 | 729 | 'de' => [ |
730 | - ['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü'], |
|
730 | + ['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü'], |
|
731 | 731 | ['ae', 'oe', 'ue', 'AE', 'OE', 'UE'], |
732 | 732 | ], |
733 | 733 | 'ro' => [ |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | foreach ($array as $values) { |
52 | 52 | if ($values instanceof Collection) { |
53 | 53 | $values = $values->all(); |
54 | - } elseif (! is_array($values)) { |
|
54 | + } elseif (!is_array($values)) { |
|
55 | 55 | continue; |
56 | 56 | } |
57 | 57 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $results = []; |
112 | 112 | |
113 | 113 | foreach ($array as $key => $value) { |
114 | - if (is_array($value) && ! empty($value)) { |
|
114 | + if (is_array($value) && !empty($value)) { |
|
115 | 115 | $results = array_merge($results, static::dot($value, $prepend.$key.'.')); |
116 | 116 | } else { |
117 | 117 | $results[$prepend.$key] = $value; |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | foreach ($array as $item) { |
212 | 212 | $item = $item instanceof Collection ? $item->all() : $item; |
213 | 213 | |
214 | - if (! is_array($item)) { |
|
214 | + if (!is_array($item)) { |
|
215 | 215 | $result[] = $item; |
216 | 216 | } elseif ($depth === 1) { |
217 | 217 | $result = array_merge($result, array_values($item)); |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | */ |
278 | 278 | public static function get($array, $key, $default = null) |
279 | 279 | { |
280 | - if (! static::accessible($array)) { |
|
280 | + if (!static::accessible($array)) { |
|
281 | 281 | return value($default); |
282 | 282 | } |
283 | 283 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | { |
316 | 316 | $keys = (array) $keys; |
317 | 317 | |
318 | - if (! $array || $keys === []) { |
|
318 | + if (!$array || $keys === []) { |
|
319 | 319 | return false; |
320 | 320 | } |
321 | 321 | |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | // If the key doesn't exist at this depth, we will just create an empty array |
518 | 518 | // to hold the next value, allowing us to create the arrays to hold final |
519 | 519 | // values at the correct depth. Then we'll keep digging into the array. |
520 | - if (! isset($array[$key]) || ! is_array($array[$key])) { |
|
520 | + if (!isset($array[$key]) || !is_array($array[$key])) { |
|
521 | 521 | $array[$key] = []; |
522 | 522 | } |
523 | 523 |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | { |
148 | 148 | $callback = $this->valueRetriever($callback); |
149 | 149 | |
150 | - $items = $this->map(function ($value) use ($callback) { |
|
150 | + $items = $this->map(function($value) use ($callback) { |
|
151 | 151 | return $callback($value); |
152 | - })->filter(function ($value) { |
|
153 | - return ! is_null($value); |
|
152 | + })->filter(function($value) { |
|
153 | + return !is_null($value); |
|
154 | 154 | }); |
155 | 155 | |
156 | 156 | if ($count = $items->count()) { |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | public function median($key = null) |
179 | 179 | { |
180 | 180 | $values = (isset($key) ? $this->pluck($key) : $this) |
181 | - ->filter(function ($item) { |
|
182 | - return ! is_null($item); |
|
181 | + ->filter(function($item) { |
|
182 | + return !is_null($item); |
|
183 | 183 | })->sort()->values(); |
184 | 184 | |
185 | 185 | $count = $values->count(); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | |
216 | 216 | $counts = new self; |
217 | 217 | |
218 | - $collection->each(function ($value) use ($counts) { |
|
218 | + $collection->each(function($value) use ($counts) { |
|
219 | 219 | $counts[$value] = isset($counts[$value]) ? $counts[$value] + 1 : 1; |
220 | 220 | }); |
221 | 221 | |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | |
224 | 224 | $highestValue = $sorted->last(); |
225 | 225 | |
226 | - return $sorted->filter(function ($value) use ($highestValue) { |
|
226 | + return $sorted->filter(function($value) use ($highestValue) { |
|
227 | 227 | return $value == $highestValue; |
228 | 228 | })->sort()->keys()->all(); |
229 | 229 | } |
@@ -284,13 +284,13 @@ discard block |
||
284 | 284 | public function containsStrict($key, $value = null) |
285 | 285 | { |
286 | 286 | if (func_num_args() === 2) { |
287 | - return $this->contains(function ($item) use ($key, $value) { |
|
287 | + return $this->contains(function($item) use ($key, $value) { |
|
288 | 288 | return data_get($item, $key) === $value; |
289 | 289 | }); |
290 | 290 | } |
291 | 291 | |
292 | 292 | if ($this->useAsCallable($key)) { |
293 | - return ! is_null($this->first($key)); |
|
293 | + return !is_null($this->first($key)); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | return in_array($key, $this->items, true); |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | { |
332 | 332 | (new static(func_get_args())) |
333 | 333 | ->push($this) |
334 | - ->each(function ($item) { |
|
334 | + ->each(function($item) { |
|
335 | 335 | VarDumper::dump($item); |
336 | 336 | }); |
337 | 337 | |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | */ |
433 | 433 | public function eachSpread(callable $callback) |
434 | 434 | { |
435 | - return $this->each(function ($chunk, $key) use ($callback) { |
|
435 | + return $this->each(function($chunk, $key) use ($callback) { |
|
436 | 436 | $chunk[] = $key; |
437 | 437 | |
438 | 438 | return $callback(...$chunk); |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | $callback = $this->valueRetriever($key); |
454 | 454 | |
455 | 455 | foreach ($this->items as $k => $v) { |
456 | - if (! $callback($v, $k)) { |
|
456 | + if (!$callback($v, $k)) { |
|
457 | 457 | return false; |
458 | 458 | } |
459 | 459 | } |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | { |
475 | 475 | if ($keys instanceof self) { |
476 | 476 | $keys = $keys->all(); |
477 | - } elseif (! is_array($keys)) { |
|
477 | + } elseif (!is_array($keys)) { |
|
478 | 478 | $keys = func_get_args(); |
479 | 479 | } |
480 | 480 | |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | */ |
550 | 550 | public function unless($value, callable $callback, callable $default = null) |
551 | 551 | { |
552 | - return $this->when(! $value, $callback, $default); |
|
552 | + return $this->when(!$value, $callback, $default); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -611,10 +611,10 @@ discard block |
||
611 | 611 | $operator = '='; |
612 | 612 | } |
613 | 613 | |
614 | - return function ($item) use ($key, $operator, $value) { |
|
614 | + return function($item) use ($key, $operator, $value) { |
|
615 | 615 | $retrieved = data_get($item, $key); |
616 | 616 | |
617 | - $strings = array_filter([$retrieved, $value], function ($value) { |
|
617 | + $strings = array_filter([$retrieved, $value], function($value) { |
|
618 | 618 | return is_string($value) || (is_object($value) && method_exists($value, '__toString')); |
619 | 619 | }); |
620 | 620 | |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | { |
663 | 663 | $values = $this->getArrayableItems($values); |
664 | 664 | |
665 | - return $this->filter(function ($item) use ($key, $values, $strict) { |
|
665 | + return $this->filter(function($item) use ($key, $values, $strict) { |
|
666 | 666 | return in_array(data_get($item, $key), $values, $strict); |
667 | 667 | }); |
668 | 668 | } |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | */ |
701 | 701 | public function whereNotBetween($key, $values) |
702 | 702 | { |
703 | - return $this->filter(function ($item) use ($key, $values) { |
|
703 | + return $this->filter(function($item) use ($key, $values) { |
|
704 | 704 | return data_get($item, $key) < reset($values) || data_get($item, $key) > end($values); |
705 | 705 | }); |
706 | 706 | } |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | { |
718 | 718 | $values = $this->getArrayableItems($values); |
719 | 719 | |
720 | - return $this->reject(function ($item) use ($key, $values, $strict) { |
|
720 | + return $this->reject(function($item) use ($key, $values, $strict) { |
|
721 | 721 | return in_array(data_get($item, $key), $values, $strict); |
722 | 722 | }); |
723 | 723 | } |
@@ -742,7 +742,7 @@ discard block |
||
742 | 742 | */ |
743 | 743 | public function whereInstanceOf($type) |
744 | 744 | { |
745 | - return $this->filter(function ($value) use ($type) { |
|
745 | + return $this->filter(function($value) use ($type) { |
|
746 | 746 | return $value instanceof $type; |
747 | 747 | }); |
748 | 748 | } |
@@ -846,14 +846,14 @@ discard block |
||
846 | 846 | foreach ($this->items as $key => $value) { |
847 | 847 | $groupKeys = $groupBy($value, $key); |
848 | 848 | |
849 | - if (! is_array($groupKeys)) { |
|
849 | + if (!is_array($groupKeys)) { |
|
850 | 850 | $groupKeys = [$groupKeys]; |
851 | 851 | } |
852 | 852 | |
853 | 853 | foreach ($groupKeys as $groupKey) { |
854 | 854 | $groupKey = is_bool($groupKey) ? (int) $groupKey : $groupKey; |
855 | 855 | |
856 | - if (! array_key_exists($groupKey, $results)) { |
|
856 | + if (!array_key_exists($groupKey, $results)) { |
|
857 | 857 | $results[$groupKey] = new static; |
858 | 858 | } |
859 | 859 | |
@@ -863,7 +863,7 @@ discard block |
||
863 | 863 | |
864 | 864 | $result = new static($results); |
865 | 865 | |
866 | - if (! empty($nextGroups)) { |
|
866 | + if (!empty($nextGroups)) { |
|
867 | 867 | return $result->map->groupBy($nextGroups, $preserveKeys); |
868 | 868 | } |
869 | 869 | |
@@ -906,7 +906,7 @@ discard block |
||
906 | 906 | $keys = is_array($key) ? $key : func_get_args(); |
907 | 907 | |
908 | 908 | foreach ($keys as $value) { |
909 | - if (! $this->offsetExists($value)) { |
|
909 | + if (!$this->offsetExists($value)) { |
|
910 | 910 | return false; |
911 | 911 | } |
912 | 912 | } |
@@ -973,7 +973,7 @@ discard block |
||
973 | 973 | */ |
974 | 974 | public function isNotEmpty() |
975 | 975 | { |
976 | - return ! $this->isEmpty(); |
|
976 | + return !$this->isEmpty(); |
|
977 | 977 | } |
978 | 978 | |
979 | 979 | /** |
@@ -984,7 +984,7 @@ discard block |
||
984 | 984 | */ |
985 | 985 | protected function useAsCallable($value) |
986 | 986 | { |
987 | - return ! is_string($value) && is_callable($value); |
|
987 | + return !is_string($value) && is_callable($value); |
|
988 | 988 | } |
989 | 989 | |
990 | 990 | /** |
@@ -1074,7 +1074,7 @@ discard block |
||
1074 | 1074 | */ |
1075 | 1075 | public function mapSpread(callable $callback) |
1076 | 1076 | { |
1077 | - return $this->map(function ($chunk, $key) use ($callback) { |
|
1077 | + return $this->map(function($chunk, $key) use ($callback) { |
|
1078 | 1078 | $chunk[] = $key; |
1079 | 1079 | |
1080 | 1080 | return $callback(...$chunk); |
@@ -1100,7 +1100,7 @@ discard block |
||
1100 | 1100 | |
1101 | 1101 | $value = reset($pair); |
1102 | 1102 | |
1103 | - if (! isset($dictionary[$key])) { |
|
1103 | + if (!isset($dictionary[$key])) { |
|
1104 | 1104 | $dictionary[$key] = []; |
1105 | 1105 | } |
1106 | 1106 | |
@@ -1167,7 +1167,7 @@ discard block |
||
1167 | 1167 | */ |
1168 | 1168 | public function mapInto($class) |
1169 | 1169 | { |
1170 | - return $this->map(function ($value, $key) use ($class) { |
|
1170 | + return $this->map(function($value, $key) use ($class) { |
|
1171 | 1171 | return new $class($value, $key); |
1172 | 1172 | }); |
1173 | 1173 | } |
@@ -1182,9 +1182,9 @@ discard block |
||
1182 | 1182 | { |
1183 | 1183 | $callback = $this->valueRetriever($callback); |
1184 | 1184 | |
1185 | - return $this->filter(function ($value) { |
|
1186 | - return ! is_null($value); |
|
1187 | - })->reduce(function ($result, $item) use ($callback) { |
|
1185 | + return $this->filter(function($value) { |
|
1186 | + return !is_null($value); |
|
1187 | + })->reduce(function($result, $item) use ($callback) { |
|
1188 | 1188 | $value = $callback($item); |
1189 | 1189 | |
1190 | 1190 | return is_null($result) || $value > $result ? $value : $result; |
@@ -1234,11 +1234,11 @@ discard block |
||
1234 | 1234 | { |
1235 | 1235 | $callback = $this->valueRetriever($callback); |
1236 | 1236 | |
1237 | - return $this->map(function ($value) use ($callback) { |
|
1237 | + return $this->map(function($value) use ($callback) { |
|
1238 | 1238 | return $callback($value); |
1239 | - })->filter(function ($value) { |
|
1240 | - return ! is_null($value); |
|
1241 | - })->reduce(function ($result, $value) { |
|
1239 | + })->filter(function($value) { |
|
1240 | + return !is_null($value); |
|
1241 | + })->reduce(function($result, $value) { |
|
1242 | 1242 | return is_null($result) || $value < $result ? $value : $result; |
1243 | 1243 | }); |
1244 | 1244 | } |
@@ -1319,7 +1319,7 @@ discard block |
||
1319 | 1319 | : $this->operatorForWhere(...func_get_args()); |
1320 | 1320 | |
1321 | 1321 | foreach ($this->items as $key => $item) { |
1322 | - $partitions[(int) ! $callback($item, $key)][$key] = $item; |
|
1322 | + $partitions[(int) !$callback($item, $key)][$key] = $item; |
|
1323 | 1323 | } |
1324 | 1324 | |
1325 | 1325 | return new static($partitions); |
@@ -1455,9 +1455,9 @@ discard block |
||
1455 | 1455 | { |
1456 | 1456 | $useAsCallable = $this->useAsCallable($callback); |
1457 | 1457 | |
1458 | - return $this->filter(function ($value, $key) use ($callback, $useAsCallable) { |
|
1458 | + return $this->filter(function($value, $key) use ($callback, $useAsCallable) { |
|
1459 | 1459 | return $useAsCallable |
1460 | - ? ! $callback($value, $key) |
|
1460 | + ? !$callback($value, $key) |
|
1461 | 1461 | : $value != $callback; |
1462 | 1462 | }); |
1463 | 1463 | } |
@@ -1481,7 +1481,7 @@ discard block |
||
1481 | 1481 | */ |
1482 | 1482 | public function search($value, $strict = false) |
1483 | 1483 | { |
1484 | - if (! $this->useAsCallable($value)) { |
|
1484 | + if (!$this->useAsCallable($value)) { |
|
1485 | 1485 | return array_search($value, $this->items, $strict); |
1486 | 1486 | } |
1487 | 1487 | |
@@ -1706,7 +1706,7 @@ discard block |
||
1706 | 1706 | |
1707 | 1707 | $callback = $this->valueRetriever($callback); |
1708 | 1708 | |
1709 | - return $this->reduce(function ($result, $item) use ($callback) { |
|
1709 | + return $this->reduce(function($result, $item) use ($callback) { |
|
1710 | 1710 | return $result + $callback($item); |
1711 | 1711 | }, 0); |
1712 | 1712 | } |
@@ -1765,7 +1765,7 @@ discard block |
||
1765 | 1765 | |
1766 | 1766 | $exists = []; |
1767 | 1767 | |
1768 | - return $this->reject(function ($item, $key) use ($callback, $strict, &$exists) { |
|
1768 | + return $this->reject(function($item, $key) use ($callback, $strict, &$exists) { |
|
1769 | 1769 | if (in_array($id = $callback($item, $key), $exists, $strict)) { |
1770 | 1770 | return true; |
1771 | 1771 | } |
@@ -1807,7 +1807,7 @@ discard block |
||
1807 | 1807 | return $value; |
1808 | 1808 | } |
1809 | 1809 | |
1810 | - return function ($item) use ($value) { |
|
1810 | + return function($item) use ($value) { |
|
1811 | 1811 | return data_get($item, $value); |
1812 | 1812 | }; |
1813 | 1813 | } |
@@ -1823,11 +1823,11 @@ discard block |
||
1823 | 1823 | */ |
1824 | 1824 | public function zip($items) |
1825 | 1825 | { |
1826 | - $arrayableItems = array_map(function ($items) { |
|
1826 | + $arrayableItems = array_map(function($items) { |
|
1827 | 1827 | return $this->getArrayableItems($items); |
1828 | 1828 | }, func_get_args()); |
1829 | 1829 | |
1830 | - $params = array_merge([function () { |
|
1830 | + $params = array_merge([function() { |
|
1831 | 1831 | return new static(func_get_args()); |
1832 | 1832 | }, $this->items], $arrayableItems); |
1833 | 1833 | |
@@ -1853,7 +1853,7 @@ discard block |
||
1853 | 1853 | */ |
1854 | 1854 | public function toArray() |
1855 | 1855 | { |
1856 | - return array_map(function ($value) { |
|
1856 | + return array_map(function($value) { |
|
1857 | 1857 | return $value instanceof Arrayable ? $value->toArray() : $value; |
1858 | 1858 | }, $this->items); |
1859 | 1859 | } |
@@ -1865,7 +1865,7 @@ discard block |
||
1865 | 1865 | */ |
1866 | 1866 | public function jsonSerialize() |
1867 | 1867 | { |
1868 | - return array_map(function ($value) { |
|
1868 | + return array_map(function($value) { |
|
1869 | 1869 | if ($value instanceof JsonSerializable) { |
1870 | 1870 | return $value->jsonSerialize(); |
1871 | 1871 | } elseif ($value instanceof Jsonable) { |
@@ -1929,12 +1929,12 @@ discard block |
||
1929 | 1929 | public function countBy($callback = null) |
1930 | 1930 | { |
1931 | 1931 | if (is_null($callback)) { |
1932 | - $callback = function ($value) { |
|
1932 | + $callback = function($value) { |
|
1933 | 1933 | return $value; |
1934 | 1934 | }; |
1935 | 1935 | } |
1936 | 1936 | |
1937 | - return new static($this->groupBy($callback)->map(function ($value) { |
|
1937 | + return new static($this->groupBy($callback)->map(function($value) { |
|
1938 | 1938 | return $value->count(); |
1939 | 1939 | })); |
1940 | 1940 | } |
@@ -2067,7 +2067,7 @@ discard block |
||
2067 | 2067 | */ |
2068 | 2068 | public function __get($key) |
2069 | 2069 | { |
2070 | - if (! in_array($key, static::$proxies)) { |
|
2070 | + if (!in_array($key, static::$proxies)) { |
|
2071 | 2071 | throw new Exception("Property [{$key}] does not exist on this collection instance."); |
2072 | 2072 | } |
2073 | 2073 |