Conditions | 3 |
Paths | 3 |
Total Lines | 15 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 3 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | 5 | public static function generate(int $times, ?callable $generator = null): Collection |
|
21 | { |
||
22 | 5 | if ($times < 0) { |
|
23 | 1 | throw new RuntimeException('The count of values ($times) must be a positive value'); |
|
24 | } |
||
25 | $generator = $generator ?? static function (int $index) { |
||
26 | 3 | return $index; |
|
27 | 4 | }; |
|
28 | |||
29 | 4 | $collection = self::toCollection(); |
|
30 | 4 | for ($i = 0; $i < $times; $i++) { |
|
31 | 4 | $collection->add($generator($i)); |
|
32 | } |
||
33 | |||
34 | 4 | return $collection; |
|
35 | } |
||
86 |