@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | public function __construct(\Closure $func, \Iterator $iterable, $reverse = false) |
| 58 | 58 | { |
| 59 | 59 | if ($reverse) { |
| 60 | - $cmp = function ($a, $b) use ($func) { |
|
| 60 | + $cmp = function($a, $b) use ($func) { |
|
| 61 | 61 | $orderA = $a['order']; |
| 62 | 62 | $orderB = $b['order']; |
| 63 | 63 | return $orderA == $orderB ? 0 : ($orderA < $orderB ? 1 : -1); |
| 64 | 64 | }; |
| 65 | 65 | } else { |
| 66 | - $cmp = function ($a, $b) use ($func) { |
|
| 66 | + $cmp = function($a, $b) use ($func) { |
|
| 67 | 67 | $orderA = $a['order']; |
| 68 | 68 | $orderB = $b['order']; |
| 69 | 69 | return $orderA == $orderB ? 0 : ($orderA < $orderB ? -1 : 1); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | $data = []; |
| 74 | 74 | foreach ($iterable as $key => $value) { |
| 75 | - $data []= array('key' => $key, 'value' => $value, 'order' => call_user_func($func, $value, $key)); |
|
| 75 | + $data [] = array('key' => $key, 'value' => $value, 'order' => call_user_func($func, $value, $key)); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $this->mergesort($data, $cmp); |
@@ -114,8 +114,9 @@ discard block |
||
| 114 | 114 | protected function mergesort(array &$array, \Closure $cmp_function) |
| 115 | 115 | { |
| 116 | 116 | // Arrays of size < 2 require no action. |
| 117 | - if (count($array) < 2) |
|
| 118 | - return; |
|
| 117 | + if (count($array) < 2) { |
|
| 118 | + return; |
|
| 119 | + } |
|
| 119 | 120 | |
| 120 | 121 | // Split the array in half |
| 121 | 122 | $halfway = count($array) / 2; |
@@ -138,15 +139,18 @@ discard block |
||
| 138 | 139 | while ($ptr1 < count($array1) && $ptr2 < count($array2)) { |
| 139 | 140 | if (call_user_func($cmp_function, $array1[$ptr1], $array2[$ptr2]) < 1) { |
| 140 | 141 | $array[] = $array1[$ptr1++]; |
| 141 | - } |
|
| 142 | - else { |
|
| 142 | + } else { |
|
| 143 | 143 | $array[] = $array2[$ptr2++]; |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // Merge the remainder |
| 148 | - while ($ptr1 < count($array1)) $array[] = $array1[$ptr1++]; |
|
| 149 | - while ($ptr2 < count($array2)) $array[] = $array2[$ptr2++]; |
|
| 148 | + while ($ptr1 < count($array1)) { |
|
| 149 | + $array[] = $array1[$ptr1++]; |
|
| 150 | + } |
|
| 151 | + while ($ptr2 < count($array2)) { |
|
| 152 | + $array[] = $array2[$ptr2++]; |
|
| 153 | + } |
|
| 150 | 154 | return; |
| 151 | 155 | } |
| 152 | 156 | } |
@@ -61,11 +61,11 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | public function __construct(\Closure $valueFunc /* [\Closure $keyFunc], \Iterator $iterable1, [\Iterator $iterable2, [...]] */) |
| 63 | 63 | { |
| 64 | - parent::__construct(\MultipleIterator::MIT_NEED_ALL| \MultipleIterator::MIT_KEYS_NUMERIC); |
|
| 64 | + parent::__construct(\MultipleIterator::MIT_NEED_ALL|\MultipleIterator::MIT_KEYS_NUMERIC); |
|
| 65 | 65 | $args = func_get_args(); |
| 66 | 66 | $argsContainsKeyFunc = $args[1] instanceof \Closure; |
| 67 | 67 | $this->valueFunc = $args[0]; |
| 68 | - $this->keyFunc = $argsContainsKeyFunc ? $args[1] : function () { return $this->genericKeysToKey(func_get_args()); }; |
|
| 68 | + $this->keyFunc = $argsContainsKeyFunc ? $args[1] : function() { return $this->genericKeysToKey(func_get_args()); }; |
|
| 69 | 69 | foreach (array_slice($args, $argsContainsKeyFunc ? 2 : 1) as $iterable) { |
| 70 | 70 | if (!$iterable instanceof \Iterator) { |
| 71 | 71 | throw new \InvalidArgumentException(sprintf('Argument %d must be an iterator')); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | foreach ($keys as $key) { |
| 87 | 87 | if ($key !== $value) { |
| 88 | 88 | // the keys are different, we will make a new string identifying this entry |
| 89 | - return join(':', array_map(function ($key) { return (string)$key; }, $keys)); |
|
| 89 | + return join(':', array_map(function($key) { return (string)$key; }, $keys)); |
|
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
@@ -160,7 +160,7 @@ |
||
| 160 | 160 | $array = iterator_to_array($this); |
| 161 | 161 | array_walk( |
| 162 | 162 | $array, |
| 163 | - function (&$value) { |
|
| 163 | + function(&$value) { |
|
| 164 | 164 | /** @var GroupedIterator $value */ |
| 165 | 165 | $value = $value->toArray(); |
| 166 | 166 | } |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | |
| 49 | 49 | public function __construct(/* \Iterator $iterable1, \Iterator $iterable2, ... */) |
| 50 | 50 | { |
| 51 | - parent::__construct(\MultipleIterator::MIT_NEED_ALL| \MultipleIterator::MIT_KEYS_NUMERIC); |
|
| 51 | + parent::__construct(\MultipleIterator::MIT_NEED_ALL|\MultipleIterator::MIT_KEYS_NUMERIC); |
|
| 52 | 52 | foreach (func_get_args() as $iterable) { |
| 53 | 53 | if (!$iterable instanceof \Iterator) { |
| 54 | 54 | throw new \InvalidArgumentException(sprintf('Argument %d must be an iterator')); |
@@ -67,7 +67,7 @@ |
||
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | $this->index = 0; |
| 70 | - $this->start = $start < 0 ? $length + $start: $start; |
|
| 70 | + $this->start = $start < 0 ? $length + $start : $start; |
|
| 71 | 71 | $this->end = $end === null ? null : ($end < 0 ? $length + $end : $end); |
| 72 | 72 | parent::__construct($iterable); |
| 73 | 73 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | function lstrip($chars = " \t\n\r\0\x0B") |
| 18 | 18 | { |
| 19 | - return function ($value) use ($chars) { |
|
| 19 | + return function($value) use ($chars) { |
|
| 20 | 20 | return ltrim($value, $chars); |
| 21 | 21 | }; |
| 22 | 22 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function rstrip($chars = " \t\n\r\0\x0B") |
| 31 | 31 | { |
| 32 | - return function ($value) use ($chars) { |
|
| 32 | + return function($value) use ($chars) { |
|
| 33 | 33 | return rtrim($value, $chars); |
| 34 | 34 | }; |
| 35 | 35 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | function strip($chars = " \t\n\r\0\x0B") |
| 44 | 44 | { |
| 45 | - return function ($value) use ($chars) { |
|
| 45 | + return function($value) use ($chars) { |
|
| 46 | 46 | return trim($value, $chars); |
| 47 | 47 | }; |
| 48 | 48 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function length() |
| 56 | 56 | { |
| 57 | - return function ($value) { |
|
| 57 | + return function($value) { |
|
| 58 | 58 | if (is_null($value)) { |
| 59 | 59 | return 0; |
| 60 | 60 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | function key() |
| 76 | 76 | { |
| 77 | - return function ($value, $key) { |
|
| 77 | + return function($value, $key) { |
|
| 78 | 78 | return $key; |
| 79 | 79 | }; |
| 80 | 80 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function lower() |
| 88 | 88 | { |
| 89 | - return function ($value) { |
|
| 89 | + return function($value) { |
|
| 90 | 90 | return strtolower($value); |
| 91 | 91 | }; |
| 92 | 92 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | function upper() |
| 100 | 100 | { |
| 101 | - return function ($value) { |
|
| 101 | + return function($value) { |
|
| 102 | 102 | return strtoupper($value); |
| 103 | 103 | }; |
| 104 | 104 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | { |
| 135 | 135 | $strategies = array_map('\Zicht\Itertools\conversions\mixedToValueGetter', $strategies); |
| 136 | 136 | |
| 137 | - return function ($value, $key) use ($strategies) { |
|
| 137 | + return function($value, $key) use ($strategies) { |
|
| 138 | 138 | $res = []; |
| 139 | 139 | foreach ($strategies as $strategyKey => $strategy) { |
| 140 | 140 | $res[$strategyKey] = $strategy($value, $key); |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $max = getrandmax(); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - return function () use ($min, $max) { |
|
| 159 | + return function() use ($min, $max) { |
|
| 160 | 160 | return rand($min, $max); |
| 161 | 161 | }; |
| 162 | 162 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | function type($strategy = null) |
| 171 | 171 | { |
| 172 | 172 | $strategy = conversions\mixedToValueGetter($strategy); |
| 173 | - return function ($value) use ($strategy) { |
|
| 173 | + return function($value) use ($strategy) { |
|
| 174 | 174 | $value = $strategy($value); |
| 175 | 175 | return is_object($value) ? get_class($value) : gettype($value); |
| 176 | 176 | }; |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | function type($class, $strategy = null) |
| 29 | 29 | { |
| 30 | 30 | $strategy = conversions\mixedToValueGetter($strategy); |
| 31 | - return function ($value) use ($class, $strategy) { |
|
| 31 | + return function($value) use ($class, $strategy) { |
|
| 32 | 32 | return $strategy($value) instanceof $class; |
| 33 | 33 | }; |
| 34 | 34 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $haystack = iter\iterable($haystack)->values(); |
| 59 | 59 | } |
| 60 | 60 | $strategy = conversions\mixedToValueGetter($strategy); |
| 61 | - return function ($value) use ($haystack, $strategy, $strict) { |
|
| 61 | + return function($value) use ($haystack, $strategy, $strict) { |
|
| 62 | 62 | return in_array($strategy($value), $haystack, $strict); |
| 63 | 63 | }; |
| 64 | 64 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | $haystack = iter\iterable($haystack)->values(); |
| 81 | 81 | } |
| 82 | 82 | $strategy = conversions\mixedToValueGetter($strategy); |
| 83 | - return function ($value) use ($haystack, $strategy, $strict) { |
|
| 83 | + return function($value) use ($haystack, $strategy, $strict) { |
|
| 84 | 84 | return !in_array($strategy($value), $haystack, $strict); |
| 85 | 85 | }; |
| 86 | 86 | } |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | $strategy = conversions\mixedToValueGetter($strategy); |
| 110 | 110 | if ($strict) { |
| 111 | - return function ($value) use ($expected, $strategy) { |
|
| 111 | + return function($value) use ($expected, $strategy) { |
|
| 112 | 112 | return $expected === $strategy($value); |
| 113 | 113 | }; |
| 114 | 114 | } else { |
| 115 | - return function ($value) use ($expected, $strategy) { |
|
| 115 | + return function($value) use ($expected, $strategy) { |
|
| 116 | 116 | return $expected == $strategy($value); |
| 117 | 117 | }; |
| 118 | 118 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | function chain(/* $iterable, $iterable2, ... */) |
| 174 | 174 | { |
| 175 | 175 | $iterables = array_map( |
| 176 | - function ($iterable) { |
|
| 176 | + function($iterable) { |
|
| 177 | 177 | return conversions\mixedToIterator($iterable); |
| 178 | 178 | }, |
| 179 | 179 | func_get_args() |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | function map($strategy, $iterable /*, $iterable2, ... */) |
| 306 | 306 | { |
| 307 | 307 | $iterables = array_map( |
| 308 | - function ($iterable) { |
|
| 308 | + function($iterable) { |
|
| 309 | 309 | return conversions\mixedToIterator($iterable); |
| 310 | 310 | }, |
| 311 | 311 | array_slice(func_get_args(), 1) |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | $strategy = conversions\mixedToValueGetter($strategy); |
| 481 | - $isValid = function ($value, $key) use ($strategy) { |
|
| 481 | + $isValid = function($value, $key) use ($strategy) { |
|
| 482 | 482 | $tempVarPhp54 = $strategy($value, $key); |
| 483 | 483 | return !empty($tempVarPhp54); |
| 484 | 484 | }; |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | switch (sizeof($args)) { |
| 504 | 504 | case 2: |
| 505 | 505 | $strategy = conversions\mixedToValueGetter($args[0]); |
| 506 | - $closure = function ($value, $key) use ($strategy) { |
|
| 506 | + $closure = function($value, $key) use ($strategy) { |
|
| 507 | 507 | $tempVarPhp54 = call_user_func($strategy, $value, $key); |
| 508 | 508 | return !empty($tempVarPhp54); |
| 509 | 509 | }; |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | case 3: |
| 514 | 514 | $strategy = conversions\mixedToValueGetter($args[0]); |
| 515 | 515 | $userClosure = $args[1]; |
| 516 | - $closure = function ($value, $key) use ($strategy, $userClosure) { |
|
| 516 | + $closure = function($value, $key) use ($strategy, $userClosure) { |
|
| 517 | 517 | return call_user_func($userClosure, call_user_func($strategy, $value, $key)); |
| 518 | 518 | }; |
| 519 | 519 | $iterable = conversions\mixedToIterator($args[2]); |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | function zip(/* $iterable, $iterable2, ... */) |
| 546 | 546 | { |
| 547 | 547 | $iterables = array_map( |
| 548 | - function ($iterable) { |
|
| 548 | + function($iterable) { |
|
| 549 | 549 | return conversions\mixedToIterator($iterable); |
| 550 | 550 | }, |
| 551 | 551 | func_get_args() |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | public static function lstrip($chars = " \t\n\r\0\x0B") |
| 18 | 18 | { |
| 19 | - return function ($value) use ($chars) { |
|
| 19 | + return function($value) use ($chars) { |
|
| 20 | 20 | return ltrim($value, $chars); |
| 21 | 21 | }; |
| 22 | 22 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public static function rstrip($chars = " \t\n\r\0\x0B") |
| 28 | 28 | { |
| 29 | - return function ($value) use ($chars) { |
|
| 29 | + return function($value) use ($chars) { |
|
| 30 | 30 | return rtrim($value, $chars); |
| 31 | 31 | }; |
| 32 | 32 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public static function strip($chars = " \t\n\r\0\x0B") |
| 38 | 38 | { |
| 39 | - return function ($value) use ($chars) { |
|
| 39 | + return function($value) use ($chars) { |
|
| 40 | 40 | return trim($value, $chars); |
| 41 | 41 | }; |
| 42 | 42 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public static function length() |
| 48 | 48 | { |
| 49 | - return function ($value) { |
|
| 49 | + return function($value) { |
|
| 50 | 50 | return sizeof($value); |
| 51 | 51 | }; |
| 52 | 52 | } |