Completed
Push — master ( a433d4...897506 )
by Kevin
06:44
created

RSMQueryIterateResult::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Zenstruck\Porpaginas\Doctrine;
4
5
use Doctrine\DBAL\Query\QueryBuilder;
6
use Doctrine\ORM\EntityManagerInterface;
7
use Doctrine\ORM\Query\ResultSetMappingBuilder;
8
use Zenstruck\Porpaginas\Result;
9
10
/**
11
 * @author Kevin Bond <[email protected]>
12
 */
13 View Code Duplication
final class RSMQueryIterateResult implements Result
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    private $child;
16
    private $em;
17
18
    /**
19
     * @param EntityManagerInterface  $em
20
     * @param ResultSetMappingBuilder $rsm
21
     * @param QueryBuilder            $qb
22
     * @param callable|null           $countQueryBuilderModifier
23
     */
24
    public function __construct(EntityManagerInterface $em, ResultSetMappingBuilder $rsm, QueryBuilder $qb, callable $countQueryBuilderModifier = null)
25
    {
26
        $this->em = $em;
27
        $this->child = new RSMQueryResult($em, $rsm, $qb, $countQueryBuilderModifier);
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function take($offset, $limit)
34
    {
35
        return $this->child->take($offset, $limit);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function count()
42
    {
43
        return $this->child->count();
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getIterator()
50
    {
51
        foreach ($this->child->getQuery()->iterate() as $row) {
52
            yield $row[0];
53
54
            $this->em->detach($row[0]);
55
        }
56
    }
57
}
58