LimitIterableAggregate::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types=1);
9
10
namespace loophp\iterators;
11
12
use Generator;
13
use IteratorAggregate;
14
use LimitIterator;
15
16
/**
17
 * @template TKey
18
 * @template T
19
 *
20
 * @implements IteratorAggregate<TKey, T>
21
 */
22
final class LimitIterableAggregate implements IteratorAggregate
23
{
24
    /**
25
     * @param iterable<TKey, T> $iterable
26
     */
27 1
    public function __construct(private iterable $iterable, private int $offset = 0, private int $limit = -1)
28
    {
29 1
    }
30
31
    /**
32
     * @return Generator<TKey, T>
33
     */
34 1
    public function getIterator(): Generator
35
    {
36 1
        yield from new LimitIterator(
37 1
            (new IterableIteratorAggregate($this->iterable))->getIterator(),
38 1
            $this->offset,
39 1
            $this->limit
40 1
        );
41
    }
42
}
43