Completed
Push — master ( 3dab41...181b76 )
by Peter
06:26
created

src/Filter/In.php (7 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * This file is part of the Happyr Doctrine Specification package.
5
 *
6
 * (c) Tobias Nyholm <[email protected]>
7
 *     Kacper Gunia <[email protected]>
8
 *     Peter Gribanov <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Happyr\DoctrineSpecification\Filter;
15
16
use Doctrine\ORM\QueryBuilder;
17
use Happyr\DoctrineSpecification\Operand\ArgumentToOperandConverter;
18
use Happyr\DoctrineSpecification\Operand\Operand;
19
20 View Code Duplication
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;
0 ignored issues
show
Deprecated Code introduced by
The property Happyr\DoctrineSpecification\Filter\In::$field has been deprecated with message: This property will be marked as private in 2.0.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
53
        $this->value = $value;
0 ignored issues
show
Deprecated Code introduced by
The property Happyr\DoctrineSpecification\Filter\In::$value has been deprecated with message: This property will be marked as private in 2.0.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
54
        $this->dqlAlias = $dqlAlias;
0 ignored issues
show
Deprecated Code introduced by
The property Happyr\DoctrineSpecification\Filter\In::$dqlAlias has been deprecated with message: This property will be marked as private in 2.0.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
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) {
0 ignored issues
show
Deprecated Code introduced by
The property Happyr\DoctrineSpecification\Filter\In::$dqlAlias has been deprecated with message: This property will be marked as private in 2.0.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
66
            $dqlAlias = $this->dqlAlias;
0 ignored issues
show
Deprecated Code introduced by
The property Happyr\DoctrineSpecification\Filter\In::$dqlAlias has been deprecated with message: This property will be marked as private in 2.0.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
67
        }
68
69
        $field = ArgumentToOperandConverter::toField($this->field);
0 ignored issues
show
Deprecated Code introduced by
The property Happyr\DoctrineSpecification\Filter\In::$field has been deprecated with message: This property will be marked as private in 2.0.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
70
        $value = ArgumentToOperandConverter::toValue($this->value);
0 ignored issues
show
Deprecated Code introduced by
The property Happyr\DoctrineSpecification\Filter\In::$value has been deprecated with message: This property will be marked as private in 2.0.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
71
72
        return (string) $qb->expr()->in(
73
            $field->transform($qb, $dqlAlias),
74
            $value->transform($qb, $dqlAlias)
75
        );
76
    }
77
}
78