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

Value::transform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 2
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