Conditions | 5 |
Paths | 8 |
Total Lines | 15 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
15 | function iterable_slice(iterable $iterable, int $offset, ?int $limit = null): \Generator |
||
16 | { |
||
17 | 16 | $counter = 0; |
|
18 | 16 | $end = isset($limit) ? ($offset + $limit) : PHP_INT_MAX; |
|
19 | |||
20 | 16 | foreach ($iterable as $key => $value) { |
|
21 | 15 | if ($counter === $end) { |
|
22 | 10 | return; |
|
23 | } |
||
24 | |||
25 | 15 | if ($counter >= $offset) { |
|
26 | 15 | yield $key => $value; |
|
27 | } |
||
28 | |||
29 | 15 | $counter++; |
|
30 | } |
||
32 |