Passed
Push — main ( 815497...f1959f )
by Pol
03:40
created

LimitIterableAggregate::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
ccs 4
cts 4
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
use Traversable;
16
17
/**
18
 * @template TKey
19
 * @template T
20
 *
21
 * @implements IteratorAggregate<TKey, T>
22
 */
23
final class LimitIterableAggregate implements IteratorAggregate
24
{
25
    /**
26
     * @var iterable<TKey, T>
27
     */
28
    private iterable $iterable;
29
30
    private int $limit;
31
32
    private int $offset;
33
34
    /**
35
     * @param iterable<TKey, T> $iterable
36
     */
37 1
    public function __construct(iterable $iterable, int $offset = 0, int $limit = -1)
38
    {
39 1
        $this->iterable = $iterable;
40 1
        $this->offset = $offset;
41 1
        $this->limit = $limit;
42 1
    }
43
44
    /**
45
     * @return Generator<TKey, T>
46
     */
47 1
    public function getIterator(): Traversable
48
    {
49 1
        yield from new LimitIterator(
50 1
            (new IterableIteratorAggregate($this->iterable))->getIterator(),
51 1
            $this->offset,
52 1
            $this->limit
53
        );
54 1
    }
55
}
56