Passed
Pull Request — 3.x (#201)
by Giso
02:52
created

TypesCondition   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A apply() 0 6 2
1
<?php
2
3
namespace DH\DoctrineAuditBundle\Reader;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Query\QueryBuilder;
7
8
class TypesCondition implements ConditionInterface
9
{
10
    /**
11
     * @var array
12
     */
13
    private $types;
14
15
    /**
16
     * Apply types filtering
17
     *
18
     * @param array $types
19
     */
20
    public function __construct($types)
21
    {
22
        $this->types = $types;
23
    }
24
25
    public function apply(QueryBuilder $queryBuilder)
26
    {
27
        if (!empty($this->types)) {
28
            $queryBuilder
29
                ->andWhere('type IN (:filters)')
30
                ->setParameter('filters', $this->types, Connection::PARAM_STR_ARRAY)
31
            ;
32
        }
33
    }
34
}
35