ORMCountableBatchProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A count() 0 3 1
A getIterator() 0 3 1
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