IsNotNull::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
dl 5
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
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
use Happyr\DoctrineSpecification\Operand\ArgumentToOperandConverter;
18
use Happyr\DoctrineSpecification\Operand\Operand;
19
20 View Code Duplication
class IsNotNull implements Filter
0 ignored issues
show
Duplication introduced by
This class 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...
21
{
22
    /**
23
     * @var Operand|string
24
     */
25
    private $field;
26
27
    /**
28
     * @var string|null
29
     */
30
    private $dqlAlias;
31
32
    /**
33
     * @param Operand|string $field
34
     * @param string|null    $dqlAlias
35
     */
36
    public function __construct($field, $dqlAlias = null)
37
    {
38
        $this->field = $field;
39
        $this->dqlAlias = $dqlAlias;
40
    }
41
42
    /**
43
     * @param QueryBuilder $qb
44
     * @param string       $dqlAlias
45
     *
46
     * @return string
47
     */
48
    public function getFilter(QueryBuilder $qb, $dqlAlias)
49
    {
50
        if (null !== $this->dqlAlias) {
51
            $dqlAlias = $this->dqlAlias;
52
        }
53
54
        $field = ArgumentToOperandConverter::toField($this->field);
55
56
        return (string) $qb->expr()->isNotNull($field->transform($qb, $dqlAlias));
57
    }
58
}
59