Completed
Pull Request — master (#2)
by Kevin
01:27
created

ORMCountableBatchProcessor::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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