| 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 | 6 | public static function generate(int $times, ?callable $generator = null): Collection |
|
| 21 | { |
||
| 22 | 6 | 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 | 4 | return $index; |
|
| 27 | 5 | }; |
|
| 28 | |||
| 29 | 5 | $collection = self::toCollection(); |
|
| 30 | 5 | for ($i = 0; $i < $times; $i++) { |
|
| 31 | 5 | $collection->add($generator($i)); |
|
| 32 | } |
||
| 33 | |||
| 34 | 5 | return $collection; |
|
| 35 | } |
||
| 86 |