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

RSMQueryIterateResult   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 3
dl 45
loc 45
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A take() 4 4 1
A count() 4 4 1
A getIterator() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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