| Total Complexity | 12 | 
| Total Lines | 74 | 
| Duplicated Lines | 0 % | 
| Coverage | 100% | 
| Changes | 3 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php | ||
| 10 | class CollectionFactory | ||
| 11 | { | ||
| 12 | use CollectionConstructorTrait; | ||
| 13 | |||
| 14 | /** | ||
| 15 | * Returns collection generated with generator <f(int $index): mixed> for $times | ||
| 16 | * @param int $times | ||
| 17 | * @param callable|null $generator | ||
| 18 | * @return Collection | ||
| 19 | */ | ||
| 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 | } | ||
| 36 | |||
| 37 | /** | ||
| 38 | * Generate collection of int numbers between $from and $to. If $to arg is absent $from - is count of numbers | ||
| 39 | * @param int $from | ||
| 40 | * @param int $to | ||
| 41 | * @return Collection | ||
| 42 | */ | ||
| 43 | 24 | public static function numbers(int $from, ?int $to = null): Collection | |
| 44 |     { | ||
| 45 | 24 |         if ($to === null) { | |
| 46 | 22 | $to = $from - 1; | |
| 47 | 22 | $from = 0; | |
| 48 | } | ||
| 49 | |||
| 50 | 24 |         if ($from > $to) { | |
| 51 | 1 |             throw new RuntimeException('FROM need to be less than TO'); | |
| 52 | } | ||
| 53 | 24 | $list = new ArrayList(); | |
| 54 | 24 |         for ($i = $from; $i <= $to; $i++) { | |
| 55 | 24 | $list->add($i); | |
| 56 | } | ||
| 57 | |||
| 58 | 24 | return $list; | |
| 59 | } | ||
| 60 | |||
| 61 | 43 | public static function from(array $values): Collection | |
| 64 | } | ||
| 65 | |||
| 66 | 1 | public static function fromStrict(array $values): Collection | |
| 69 | } | ||
| 70 | |||
| 71 | 1 | public static function fromIterable(iterable $iterable): Collection | |
| 79 | } | ||
| 80 | |||
| 81 | 7 | public static function empty(): Collection | |
| 86 |