@@ -60,6 +60,10 @@ |
||
| 60 | 60 | private $start; |
| 61 | 61 | private $end; |
| 62 | 62 | |
| 63 | + /** |
|
| 64 | + * @param integer $start |
|
| 65 | + * @param integer $end |
|
| 66 | + */ |
|
| 63 | 67 | public function __construct(\Iterator $iterable, $start, $end = null) |
| 64 | 68 | { |
| 65 | 69 | if ($start < 0 || $end < 0) { |
@@ -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 | } |
@@ -26,8 +26,6 @@ |
||
| 26 | 26 | * > iter\iterable('ABC', 'DEF')->chain() |
| 27 | 27 | * A B C D E F |
| 28 | 28 | * |
| 29 | - * @param array|string|\Iterator $iterable |
|
| 30 | - * @param array|string|\Iterator $iterable2 |
|
| 31 | 29 | * @return iter\lib\ChainIterator |
| 32 | 30 | */ |
| 33 | 31 | public function chain(/* $iterable, $iterable2, ... */) |
@@ -34,7 +34,6 @@ |
||
| 34 | 34 | * 2.5 3.5 4.5 |
| 35 | 35 | * |
| 36 | 36 | * @param null|string|\Closure $strategy |
| 37 | - * @param array|string|\Iterator $iterable2 |
|
| 38 | 37 | * @return iter\lib\MapIterator |
| 39 | 38 | */ |
| 40 | 39 | public function map($strategy /*, $iterable2, ... */) |
@@ -25,7 +25,6 @@ |
||
| 25 | 25 | * > iter\iterable([])->reduce('min', 1) |
| 26 | 26 | * 1 |
| 27 | 27 | * |
| 28 | - * @param array|string|\Iterator $iterable |
|
| 29 | 28 | * @param string|\Closure $closure |
| 30 | 29 | * @param mixed $initializer |
| 31 | 30 | * @return mixed |
@@ -22,7 +22,6 @@ |
||
| 22 | 22 | * > zip([1, 2, 3], ['a', 'b', 'c']) |
| 23 | 23 | * [1, 'a'] [2, 'b'] [3, 'c'] |
| 24 | 24 | * |
| 25 | - * @param array|string|\Iterator $iterable2 |
|
| 26 | 25 | * @return iter\lib\ZipIterator |
| 27 | 26 | */ |
| 28 | 27 | public function zip(/* $iterable2, ... */) |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | function add() |
| 17 | 17 | { |
| 18 | - return function ($a, $b) { |
|
| 18 | + return function($a, $b) { |
|
| 19 | 19 | if (!is_numeric($a)) { |
| 20 | 20 | throw new \InvalidArgumentException('Argument $A must be numeric to perform addition'); |
| 21 | 21 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function sub() |
| 35 | 35 | { |
| 36 | - return function ($a, $b) { |
|
| 36 | + return function($a, $b) { |
|
| 37 | 37 | if (!is_numeric($a)) { |
| 38 | 38 | throw new \InvalidArgumentException('Argument $A must be numeric to perform subtraction'); |
| 39 | 39 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | function mul() |
| 53 | 53 | { |
| 54 | - return function ($a, $b) { |
|
| 54 | + return function($a, $b) { |
|
| 55 | 55 | if (!is_numeric($a)) { |
| 56 | 56 | throw new \InvalidArgumentException('Argument $A must be numeric to perform multiplication'); |
| 57 | 57 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | function min() |
| 71 | 71 | { |
| 72 | - return function ($a, $b) { |
|
| 72 | + return function($a, $b) { |
|
| 73 | 73 | if (!is_numeric($a)) { |
| 74 | 74 | throw new \InvalidArgumentException('Argument $A must be numeric to determine minimum'); |
| 75 | 75 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | function max() |
| 89 | 89 | { |
| 90 | - return function ($a, $b) { |
|
| 90 | + return function($a, $b) { |
|
| 91 | 91 | if (!is_numeric($a)) { |
| 92 | 92 | throw new \InvalidArgumentException('Argument $A must be numeric to determine maximum'); |
| 93 | 93 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | if (!is_string($glue)) { |
| 110 | 110 | throw new \InvalidArgumentException('Argument $GLUE must be a string to join'); |
| 111 | 111 | } |
| 112 | - return function ($a, $b) use ($glue) { |
|
| 112 | + return function($a, $b) use ($glue) { |
|
| 113 | 113 | if (!is_string($a)) { |
| 114 | 114 | throw new \InvalidArgumentException('Argument $A must be a string to join'); |
| 115 | 115 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | function chain() |
| 133 | 133 | { |
| 134 | - return function ($chainIterator, $b) { |
|
| 134 | + return function($chainIterator, $b) { |
|
| 135 | 135 | if (!($chainIterator instanceof ChainIterator)) { |
| 136 | 136 | throw new \InvalidArgumentException('Argument $A must be a ChainIterator. Did your call "reduce" with "new ChainIterator()" as the initial parameter?'); |
| 137 | 137 | } |
@@ -176,6 +176,7 @@ |
||
| 176 | 176 | |
| 177 | 177 | /** |
| 178 | 178 | * @deprecated please use the reduction functions directly, will be removed in version 3.0 |
| 179 | + * @param string $name |
|
| 179 | 180 | */ |
| 180 | 181 | function getReduction($name) |
| 181 | 182 | { |