Completed
Push — 1.0 ( b7886a...4c0b42 )
by Peter
07:48 queued 11s
created

In::getParameterName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Happyr\DoctrineSpecification\Filter;
4
5
use Doctrine\ORM\QueryBuilder;
6
use Happyr\DoctrineSpecification\Operand\ArgumentToOperandConverter;
7
use Happyr\DoctrineSpecification\Operand\Operand;
8
9
class In implements Filter
10
{
11
    /**
12
     * @var Operand|string
13
     */
14
    protected $field;
15
16
    /**
17
     * @var Operand|mixed
18
     */
19
    protected $value;
20
21
    /**
22
     * @var string
23
     */
24
    protected $dqlAlias;
25
26
    /**
27
     * Make sure the $field has a value equals to $value.
28
     *
29
     * @param Operand|string $field
30
     * @param Operand|mixed  $value
31
     * @param string|null    $dqlAlias
32
     */
33
    public function __construct($field, $value, $dqlAlias = null)
34
    {
35
        $this->field = $field;
36
        $this->value = $value;
37
        $this->dqlAlias = $dqlAlias;
38
    }
39
40
    /**
41
     * @param QueryBuilder $qb
42
     * @param string       $dqlAlias
43
     *
44
     * @return string
45
     */
46 View Code Duplication
    public function getFilter(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...
47
    {
48
        if (null !== $this->dqlAlias) {
49
            $dqlAlias = $this->dqlAlias;
50
        }
51
52
        $field = ArgumentToOperandConverter::toField($this->field);
53
        $value = ArgumentToOperandConverter::toValue($this->value);
54
55
        return (string) $qb->expr()->in(
56
            $field->transform($qb, $dqlAlias),
57
            $value->transform($qb, $dqlAlias)
58
        );
59
    }
60
}
61