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

In   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 89.66 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A getFilter() 9 14 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 In 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
     * @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