Code Duplication    Length = 50-52 lines in 2 locations

src/Filter/In.php 1 location

@@ 20-71 (lines=52) @@
17
use Happyr\DoctrineSpecification\Operand\ArgumentToOperandConverter;
18
use Happyr\DoctrineSpecification\Operand\Operand;
19
20
class In implements Filter
21
{
22
    /**
23
     * @deprecated This property will be marked as private in 2.0.
24
     *
25
     * @var Operand|string
26
     */
27
    protected $field;
28
29
    /**
30
     * @deprecated This property will be marked as private in 2.0.
31
     *
32
     * @var Operand|mixed
33
     */
34
    protected $value;
35
36
    /**
37
     * @deprecated This property will be marked as private in 2.0.
38
     *
39
     * @var string|null
40
     */
41
    protected $dqlAlias;
42
43
    /**
44
     * Make sure the $field has a value equals to $value.
45
     *
46
     * @param Operand|string $field
47
     * @param Operand|mixed  $value
48
     * @param string|null    $dqlAlias
49
     */
50
    public function __construct($field, $value, $dqlAlias = null)
51
    {
52
        $this->field = $field;
53
        $this->value = $value;
54
        $this->dqlAlias = $dqlAlias;
55
    }
56
57
    /**
58
     * @param QueryBuilder $qb
59
     * @param string       $dqlAlias
60
     *
61
     * @return string
62
     */
63
    public function getFilter(QueryBuilder $qb, $dqlAlias)
64
    {
65
        if (null !== $this->dqlAlias) {
66
            $dqlAlias = $this->dqlAlias;
67
        }
68
69
        $field = ArgumentToOperandConverter::toField($this->field);
70
        $value = ArgumentToOperandConverter::toValue($this->value);
71
72
        return (string) $qb->expr()->in(
73
            $field->transform($qb, $dqlAlias),
74
            $value->transform($qb, $dqlAlias)

src/Filter/MemberOfX.php 1 location

@@ 20-69 (lines=50) @@
17
use Happyr\DoctrineSpecification\Operand\ArgumentToOperandConverter;
18
use Happyr\DoctrineSpecification\Operand\Operand;
19
20
class MemberOfX implements Filter
21
{
22
    /**
23
     * @var Operand|string
24
     */
25
    private $field;
26
27
    /**
28
     * @var Operand|string
29
     */
30
    private $value;
31
32
    /**
33
     * @var string|null
34
     */
35
    private $dqlAlias;
36
37
    /**
38
     * @param Operand|string $value
39
     * @param Operand|string $field
40
     * @param string|null    $dqlAlias
41
     */
42
    public function __construct($value, $field, $dqlAlias = null)
43
    {
44
        $this->value = $value;
45
        $this->field = $field;
46
        $this->dqlAlias = $dqlAlias;
47
    }
48
49
    /**
50
     * @param QueryBuilder $qb
51
     * @param string       $dqlAlias
52
     *
53
     * @return string
54
     */
55
    public function getFilter(QueryBuilder $qb, $dqlAlias)
56
    {
57
        if (null !== $this->dqlAlias) {
58
            $dqlAlias = $this->dqlAlias;
59
        }
60
61
        $field = ArgumentToOperandConverter::toField($this->field);
62
        $value = ArgumentToOperandConverter::toValue($this->value);
63
64
        return $qb->expr()->isMemberOf(
65
            $value->transform($qb, $dqlAlias),
66
            $field->transform($qb, $dqlAlias)
67
        );
68
    }
69
}
70