-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update
RandomIterableAggregate
(#53)
Remove recursivity
- Loading branch information
Showing
6 changed files
with
202 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
parameters: | ||
ignoreErrors: | ||
- | ||
message: "#^While loop condition is always true\\.$#" | ||
count: 1 | ||
path: src/RandomIntegerAggregate.php | ||
|
||
- | ||
message: "#^Parameter \\#1 \\$iterable of class loophp\\\\iterators\\\\UnpackIterableAggregate constructor expects iterable\\<\\(int\\|string\\), array\\{TKey, T\\}\\>, loophp\\\\iterators\\\\UnpackIterableAggregate\\<array\\{TKey, T\\}\\|int\\|null, array\\{TKey, T\\}\\|int\\|null\\> given\\.$#" | ||
count: 1 | ||
path: src/RandomIterableAggregate.php | ||
|
||
- | ||
message: "#^Parameter \\#1 \\$iterable of class loophp\\\\iterators\\\\UnpackIterableAggregate constructor expects iterable\\<\\(int\\|string\\), array\\{array\\{TKey, T\\}\\|int\\|null, array\\{TKey, T\\}\\|int\\|null\\}\\>, loophp\\\\iterators\\\\SortIterableAggregate\\<array\\<int, int\\|null\\>, array\\<int, array\\{TKey, T\\}\\|int\\|null\\>\\> given\\.$#" | ||
count: 1 | ||
path: src/RandomIterableAggregate.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
includes: | ||
- phpstan-baseline.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace loophp\iterators; | ||
|
||
use Generator; | ||
use IteratorAggregate; | ||
|
||
use const PHP_INT_MAX; | ||
|
||
/** | ||
* @implements IteratorAggregate<int, int> | ||
*/ | ||
final class RandomIntegerAggregate implements IteratorAggregate | ||
{ | ||
public function __construct( | ||
private readonly ?int $seed = null, | ||
private readonly int $min = 0, | ||
private readonly int $max = PHP_INT_MAX, | ||
) {} | ||
|
||
/** | ||
* @return Generator<int, int> | ||
*/ | ||
public function getIterator(): Generator | ||
{ | ||
if (null !== $this->seed) { | ||
mt_srand($this->seed); | ||
} | ||
|
||
while (true) { | ||
yield mt_rand($this->min, $this->max); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters