Completed
Push — master ( 0bc2a3...83b98a )
by Peter
05:59 queued 10s
created

IndexBy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Happyr\DoctrineSpecification\Query;
4
5
use Doctrine\ORM\QueryBuilder;
6
7
/**
8
 * Class IndexBy.
9
 */
10
class IndexBy implements QueryModifier
11
{
12
    /**
13
     * Field name.
14
     *
15
     * @var string
16
     */
17
    private $field;
18
19
    /**
20
     * DQL Alias.
21
     *
22
     * @var string
23
     */
24
    private $dqlAlias;
25
26
    /**
27
     * IndexBy constructor.
28
     *
29
     * @param string $field    Field name for indexing
30
     * @param string $dqlAlias DQL alias of field
31
     */
32
    public function __construct($field, $dqlAlias = null)
33
    {
34
        $this->field = $field;
35
        $this->dqlAlias = $dqlAlias;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 View Code Duplication
    public function modify(QueryBuilder $qb, $dqlAlias)
0 ignored issues
show
Duplication introduced by
This method 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...
42
    {
43
        if (null !== $this->dqlAlias) {
44
            $dqlAlias = $this->dqlAlias;
45
        }
46
47
        $qb->indexBy($dqlAlias, sprintf('%s.%s', $dqlAlias, $this->field));
48
    }
49
}
50