IsNotNull   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 39
loc 39
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A getFilter() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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