@@ -27,8 +27,9 @@ discard block |
||
| 27 | 27 | yield $v; |
| 28 | 28 | $isEmpty = false; |
| 29 | 29 | } |
| 30 | - if ($isEmpty) |
|
| 31 | - throw new \UnexpectedValueException(Errors::NO_ELEMENTS); |
|
| 30 | + if ($isEmpty) { |
|
| 31 | + throw new \UnexpectedValueException(Errors::NO_ELEMENTS); |
|
| 32 | + } |
|
| 32 | 33 | } |
| 33 | 34 | }); |
| 34 | 35 | } |
@@ -63,16 +64,17 @@ discard block |
||
| 63 | 64 | public static function from ($source) |
| 64 | 65 | { |
| 65 | 66 | $it = null; |
| 66 | - if ($source instanceof Enumerable) |
|
| 67 | - return $source; |
|
| 68 | - else if (is_array($source)) |
|
| 69 | - $it = new \ArrayIterator($source); |
|
| 70 | - elseif ($source instanceof \Iterator) |
|
| 71 | - $it = $source; |
|
| 72 | - elseif ($source instanceof \IteratorAggregate) |
|
| 73 | - $it = $source->getIterator(); |
|
| 74 | - elseif ($source instanceof \Traversable) |
|
| 75 | - $it = self::fromTraversable($source); |
|
| 67 | + if ($source instanceof Enumerable) { |
|
| 68 | + return $source; |
|
| 69 | + } else if (is_array($source)) { |
|
| 70 | + $it = new \ArrayIterator($source); |
|
| 71 | + } elseif ($source instanceof \Iterator) { |
|
| 72 | + $it = $source; |
|
| 73 | + } elseif ($source instanceof \IteratorAggregate) { |
|
| 74 | + $it = $source->getIterator(); |
|
| 75 | + } elseif ($source instanceof \Traversable) { |
|
| 76 | + $it = self::fromTraversable($source); |
|
| 77 | + } |
|
| 76 | 78 | if ($it !== null) { |
| 77 | 79 | return new self($it, false); |
| 78 | 80 | } |
@@ -81,8 +83,9 @@ discard block |
||
| 81 | 83 | |
| 82 | 84 | private static function fromTraversable ($source) |
| 83 | 85 | { |
| 84 | - foreach ($source as $k => $v) |
|
| 85 | - yield $k => $v; |
|
| 86 | + foreach ($source as $k => $v) { |
|
| 87 | + yield $k => $v; |
|
| 88 | + } |
|
| 86 | 89 | } |
| 87 | 90 | |
| 88 | 91 | /** |
@@ -127,8 +130,9 @@ discard block |
||
| 127 | 130 | { |
| 128 | 131 | return new self(function () use ($start, $step) { |
| 129 | 132 | $value = $start - $step; |
| 130 | - while (true) |
|
| 131 | - yield $value += $step; |
|
| 133 | + while (true) { |
|
| 134 | + yield $value += $step; |
|
| 135 | + } |
|
| 132 | 136 | }); |
| 133 | 137 | } |
| 134 | 138 | |
@@ -188,12 +192,14 @@ discard block |
||
| 188 | 192 | */ |
| 189 | 193 | public static function range ($start, $count, $step = 1) |
| 190 | 194 | { |
| 191 | - if ($count <= 0) |
|
| 192 | - return self::emptyEnum(); |
|
| 195 | + if ($count <= 0) { |
|
| 196 | + return self::emptyEnum(); |
|
| 197 | + } |
|
| 193 | 198 | return new self(function () use ($start, $count, $step) { |
| 194 | 199 | $value = $start - $step; |
| 195 | - while ($count-- > 0) |
|
| 196 | - yield $value += $step; |
|
| 200 | + while ($count-- > 0) { |
|
| 201 | + yield $value += $step; |
|
| 202 | + } |
|
| 197 | 203 | }); |
| 198 | 204 | } |
| 199 | 205 | |
@@ -227,16 +233,18 @@ discard block |
||
| 227 | 233 | */ |
| 228 | 234 | public static function rangeTo ($start, $end, $step = 1) |
| 229 | 235 | { |
| 230 | - if ($step <= 0) |
|
| 231 | - throw new \InvalidArgumentException(Errors::STEP_NEGATIVE); |
|
| 236 | + if ($step <= 0) { |
|
| 237 | + throw new \InvalidArgumentException(Errors::STEP_NEGATIVE); |
|
| 238 | + } |
|
| 232 | 239 | return new self(function () use ($start, $end, $step) { |
| 233 | 240 | if ($start <= $end) { |
| 234 | - for ($i = $start; $i < $end; $i += $step) |
|
| 235 | - yield $i; |
|
| 236 | - } |
|
| 237 | - else { |
|
| 238 | - for ($i = $start; $i > $end; $i -= $step) |
|
| 239 | - yield $i; |
|
| 241 | + for ($i = $start; $i < $end; $i += $step) { |
|
| 242 | + yield $i; |
|
| 243 | + } |
|
| 244 | + } else { |
|
| 245 | + for ($i = $start; $i > $end; $i -= $step) { |
|
| 246 | + yield $i; |
|
| 247 | + } |
|
| 240 | 248 | } |
| 241 | 249 | }); |
| 242 | 250 | } |
@@ -256,11 +264,13 @@ discard block |
||
| 256 | 264 | */ |
| 257 | 265 | public static function repeat ($element, $count = null) |
| 258 | 266 | { |
| 259 | - if ($count < 0) |
|
| 260 | - throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO); |
|
| 267 | + if ($count < 0) { |
|
| 268 | + throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO); |
|
| 269 | + } |
|
| 261 | 270 | return new self(function () use ($element, $count) { |
| 262 | - for ($i = 0; $i < $count || $count === null; $i++) |
|
| 263 | - yield $element; |
|
| 271 | + for ($i = 0; $i < $count || $count === null; $i++) { |
|
| 272 | + yield $element; |
|
| 273 | + } |
|
| 264 | 274 | }); |
| 265 | 275 | } |
| 266 | 276 | |