Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

EnumerationFilterType::apply()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 17

Duplication

Lines 8
Ratio 47.06 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 0
Metric Value
dl 8
loc 17
ccs 12
cts 12
cp 1
rs 9.3888
c 0
b 0
f 0
cc 5
nc 4
nop 2
crap 5
1
<?php
2
3
namespace Kunstmaan\AdminListBundle\AdminList\FilterType\ORM;
4
5
use Symfony\Component\HttpFoundation\Request;
6
7
/**
8
 * EnumerationFilterType
9
 */
10
class EnumerationFilterType extends AbstractORMFilterType
11
{
12
    /**
13
     * @param Request $request  The request
14
     * @param array   &$data    The data
15
     * @param string  $uniqueId The unique identifier
16
     */
17 1
    public function bindRequest(Request $request, array &$data, $uniqueId)
18
    {
19 1
        $data['comparator'] = $request->query->get('filter_comparator_' . $uniqueId);
20 1
        $data['value'] = $request->query->get('filter_value_' . $uniqueId);
21 1
    }
22
23
    /**
24
     * @param array  $data     The data
25
     * @param string $uniqueId The unique identifier
26
     */
27 2
    public function apply(array $data, $uniqueId)
28
    {
29 2
        if (isset($data['value']) && isset($data['comparator'])) {
30 2
            switch ($data['comparator']) {
31 2 View Code Duplication
                case 'in':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
32 1
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->in($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
33 1
                    $this->queryBuilder->setParameter('var_' . $uniqueId, $data['value'], \Doctrine\DBAL\Connection::PARAM_STR_ARRAY);
34
35 1
                    break;
36 1 View Code Duplication
                case 'notin':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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 1
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->notIn($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
38 1
                    $this->queryBuilder->setParameter('var_' . $uniqueId, $data['value'], \Doctrine\DBAL\Connection::PARAM_STR_ARRAY);
39
40 1
                    break;
41
            }
42
        }
43 2
    }
44
45
    /**
46
     * @return string
47
     */
48 1
    public function getTemplate()
49
    {
50 1
        return 'KunstmaanAdminListBundle:FilterType:enumerationFilter.html.twig';
51
    }
52
}
53