Passed
Push — master ( 6028dd...89a59a )
by Vitaliy
02:15
created

FilterHandler::applyInternal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 7
nop 1
crap 1
1
<?php
2
3
namespace Nayjest\Querying\Handler\Doctrine;
4
5
use Nayjest\Querying\Handler\AbstractHandler;
6
use Nayjest\Querying\Handler\DatabaseFilterHandlerTrait;
7
use Nayjest\Querying\Operation\FilterOperation;
8
use Doctrine\DBAL\Query\QueryBuilder;
9
10
/**
11
 * FilterOperation handler for Doctrine.
12
 *
13
 * @see FilterOperation
14
 */
15
class FilterHandler extends AbstractHandler
16
{
17
    use DatabaseOperationHandlerTrait;
18
    use DatabaseFilterHandlerTrait;
19
20
    /**
21
     * @param QueryBuilder $queryBuilder
22
     */
23 1
    protected function applyInternal(QueryBuilder $queryBuilder)
24
    {
25
        /** @var FilterOperation $operation */
26 1
        $operation = $this->operation;
27 1
        list($operator, $value) = $this->getOperatorAndValue();
28 1
        $fieldName = $operation->getField();
29 1
        $parameterName = 'p' . md5($fieldName . $operator);
30 1
        $queryBuilder->andWhere("$fieldName $operator :$parameterName");
31 1
        $queryBuilder->setParameter($parameterName, $value);
32 1
    }
33
}
34