mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-12-03 10:08:33 +01:00
[Iter] cs fix
This commit is contained in:
parent
1aad753ca2
commit
4e8c2ffaf7
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ function range($start, $end, $step = null): Iterator
|
||||
return Internal\lazy_iterator(
|
||||
/**
|
||||
* @return Generator<int, T, mixed, void>
|
||||
*
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user