Values   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A transform() 0 12 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\Operand;
15
16
use Doctrine\ORM\QueryBuilder;
17
use Happyr\DoctrineSpecification\ValueConverter;
18
19
class Values implements Operand
20
{
21
    /**
22
     * @var array
23
     */
24
    private $values;
25
26
    /**
27
     * @var int|string|null
28
     */
29
    private $valueType;
30
31
    /**
32
     * @param array           $values
33
     * @param int|string|null $valueType PDO::PARAM_* or \Doctrine\DBAL\Types\Type::* constant
34
     */
35
    public function __construct($values, $valueType = null)
36
    {
37
        $this->values = $values;
38
        $this->valueType = $valueType;
39
    }
40
41
    /**
42
     * @param QueryBuilder $qb
43
     * @param string       $dqlAlias
44
     *
45
     * @return string
46
     */
47
    public function transform(QueryBuilder $qb, $dqlAlias)
48
    {
49
        $values = $this->values;
50
        foreach ($values as $k => $v) {
51
            $values[$k] = ValueConverter::convertToDatabaseValue($v, $qb);
52
        }
53
54
        $paramName = sprintf('comparison_%d', $qb->getParameters()->count());
55
        $qb->setParameter($paramName, $values, $this->valueType);
56
57
        return sprintf(':%s', $paramName);
58
    }
59
}
60