Completed
Push — 1.0 ( b7886a...4c0b42 )
by Peter
07:48 queued 11s
created

Value   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 21.62 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 8
loc 37
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A transform() 8 8 1

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
namespace Happyr\DoctrineSpecification\Operand;
4
5
use Doctrine\ORM\QueryBuilder;
6
use Happyr\DoctrineSpecification\ValueConverter;
7
8
class Value implements Operand
9
{
10
    /**
11
     * @var mixed
12
     */
13
    private $value;
14
15
    /**
16
     * @var int|string|null
17
     */
18
    private $valueType;
19
20
    /**
21
     * @param mixed           $value
22
     * @param int|string|null $valueType PDO::PARAM_* or \Doctrine\DBAL\Types\Type::* constant
23
     */
24
    public function __construct($value, $valueType = null)
25
    {
26
        $this->value = $value;
27
        $this->valueType = $valueType;
28
    }
29
30
    /**
31
     * @param QueryBuilder $qb
32
     * @param string       $dqlAlias
33
     *
34
     * @return string
35
     */
36 View Code Duplication
    public function transform(QueryBuilder $qb, $dqlAlias)
0 ignored issues
show
Duplication introduced by
This method 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...
37
    {
38
        $paramName = sprintf('comparison_%d', $qb->getParameters()->count());
39
        $value = ValueConverter::convertToDatabaseValue($this->value, $qb);
40
        $qb->setParameter($paramName, $value, $this->valueType);
41
42
        return sprintf(':%s', $paramName);
43
    }
44
}
45