ORMCountableBatchProcessor::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
crap 2
1
<?php
2
3
namespace Zenstruck\Porpaginas\Doctrine\Batch;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
7
/**
8
 * @author Kevin Bond <[email protected]>
9
 */
10
final class ORMCountableBatchProcessor implements \IteratorAggregate, \Countable
11
{
12
    private ORMBatchProcessor $batchProcessor;
13
    private iterable $countable;
14
15
    /**
16
     * @param iterable $items Must be countable
17
     */
18 12
    public function __construct(iterable $items, EntityManagerInterface $em, int $chunkSize = 100)
19
    {
20 12
        if (!\is_countable($items)) {
21 1
            throw new \InvalidArgumentException('$items must be countable.');
22
        }
23
24 11
        $this->batchProcessor = new ORMBatchProcessor($items, $em, $chunkSize);
25 11
        $this->countable = &$items;
26 11
    }
27
28 11
    public function getIterator(): \Traversable
29
    {
30 11
        yield from $this->batchProcessor;
31 11
    }
32
33 11
    public function count(): int
34
    {
35 11
        return \count($this->countable);
36
    }
37
}
38