InstanceOfX::getFilter()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
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
18
class InstanceOfX implements Filter
19
{
20
    /**
21
     * @var string
22
     */
23
    private $value;
24
25
    /**
26
     * @var string|null
27
     */
28
    private $dqlAlias;
29
30
    /**
31
     * @param string      $value
32
     * @param string|null $dqlAlias
33
     */
34
    public function __construct($value, $dqlAlias = null)
35
    {
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
    public function getFilter(QueryBuilder $qb, $dqlAlias)
47
    {
48
        if (null !== $this->dqlAlias) {
49
            $dqlAlias = $this->dqlAlias;
50
        }
51
52
        return sprintf('%s INSTANCE OF %s', $dqlAlias, $this->value);
53
    }
54
}
55