Passed
Pull Request — 3.x (#201)
by Giso
02:58
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
4
namespace DH\DoctrineAuditBundle\Reader;
5
6
7
use Doctrine\DBAL\Connection;
8
use Doctrine\DBAL\Query\QueryBuilder;
9
10
class TypesCondition implements ConditionInterface
11
{
12
    /**
13
     * @var array
14
     */
15
    private $types;
16
17
    /**
18
     * Apply types filtering
19
     *
20
     * @param array $types
21
     */
22
    public function __construct($types)
23
    {
24
        $this->types = $types;
25
    }
26
27
    public function apply(QueryBuilder $queryBuilder)
28
    {
29
        if (!empty($this->types)) {
30
            $queryBuilder
31
                ->andWhere('type IN (:filters)')
32
                ->setParameter('filters', $this->types, Connection::PARAM_STR_ARRAY)
33
            ;
34
        }
35
    }
36
}
37