diff --git a/src/Psl/Iter/Iterator.php b/src/Psl/Iter/Iterator.php index 6a26c0b..3f77008 100644 --- a/src/Psl/Iter/Iterator.php +++ b/src/Psl/Iter/Iterator.php @@ -159,7 +159,7 @@ final class Iterator implements SeekableIterator, Countable } if ($this->generator) { - while($this->position !== $position) { + while ($this->position !== $position) { Psl\invariant($this->generator->valid(), 'Position is out-of-bounds.'); $this->next(); } diff --git a/src/Psl/Iter/filter_nulls.php b/src/Psl/Iter/filter_nulls.php index 12e7217..c05def1 100644 --- a/src/Psl/Iter/filter_nulls.php +++ b/src/Psl/Iter/filter_nulls.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Psl\Iter; -use Psl\Internal; use Generator; +use Psl\Internal; /** * Filter out null values from the given iterable. @@ -22,9 +22,9 @@ use Generator; */ function filter_nulls(iterable $iterable): Iterator { - return Internal\lazy_iterator(static function() use($iterable): Generator { - foreach($iterable as $value) { - if ($value !== null) { + return Internal\lazy_iterator(static function () use ($iterable): Generator { + foreach ($iterable as $value) { + if (null !== $value) { yield $value; } } diff --git a/src/Psl/Iter/range.php b/src/Psl/Iter/range.php index c162acd..15088cd 100644 --- a/src/Psl/Iter/range.php +++ b/src/Psl/Iter/range.php @@ -43,7 +43,7 @@ function range($start, $end, $step = null): Iterator return Internal\lazy_iterator( /** * @return Generator - * + * * @see https://github.com/vimeo/psalm/issues/2152#issuecomment-533363310 * * @psalm-suppress InvalidReturnType @@ -52,36 +52,37 @@ function range($start, $end, $step = null): Iterator * @psalm-suppress DocblockTypeContradiction */ static function () use ($start, $end, $step): Generator { - if ((float) $start === (float) $end) { - yield $start; - } elseif ($start < $end) { - if (null === $step) { - /** @psalm-var T $step */ - $step = 1; - } else { - Psl\invariant($step > 0, 'If start < end, the step must be positive'); - } + if ((float) $start === (float) $end) { + yield $start; + } elseif ($start < $end) { + if (null === $step) { + /** @psalm-var T $step */ + $step = 1; + } else { + Psl\invariant($step > 0, 'If start < end, the step must be positive'); + } - Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.'); - for ($i = $start; $i <= $end; $i += $step) { - Psl\invariant(is_int($i) || is_float($i), '$i must be either an integer or a float.'); Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.'); - yield $i; - } - } else { - if (null === $step) { - /** @psalm-var T $step */ - $step = -1; + for ($i = $start; $i <= $end; $i += $step) { + Psl\invariant(is_int($i) || is_float($i), '$i must be either an integer or a float.'); + Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.'); + yield $i; + } } else { - Psl\invariant($step < 0, 'If start > end, the step must be negative'); - } + if (null === $step) { + /** @psalm-var T $step */ + $step = -1; + } else { + Psl\invariant($step < 0, 'If start > end, the step must be negative'); + } - Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.'); - for ($i = $start; $i >= $end; $i += $step) { - Psl\invariant(is_int($i) || is_float($i), '$i must be either an integer or a float.'); Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.'); - yield $i; + for ($i = $start; $i >= $end; $i += $step) { + Psl\invariant(is_int($i) || is_float($i), '$i must be either an integer or a float.'); + Psl\invariant(is_int($step) || is_float($step), '$step must be either an integer or a float.'); + yield $i; + } } } - }); + ); } diff --git a/src/Psl/Iter/repeat.php b/src/Psl/Iter/repeat.php index a228af7..c233091 100644 --- a/src/Psl/Iter/repeat.php +++ b/src/Psl/Iter/repeat.php @@ -34,7 +34,7 @@ function repeat($value, ?int $num = null): Iterator { Psl\invariant(null === $num || $num >= 0, 'Number of repetitions must be non-negative'); - return Internal\lazy_iterator(static function () use($value, $num): Generator { + return Internal\lazy_iterator(static function () use ($value, $num): Generator { if (null === $num) { /** @var int $num */ $num = Math\INFINITY;