Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

NumberFilterType::apply()   B

Complexity

Conditions 10
Paths 10

Size

Total Lines 40

Duplication

Lines 40
Ratio 100 %

Code Coverage

Tests 29
CRAP Score 10

Importance

Changes 0
Metric Value
dl 40
loc 40
ccs 29
cts 29
cp 1
rs 7.6666
c 0
b 0
f 0
cc 10
nc 10
nop 2
crap 10

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Kunstmaan\AdminListBundle\AdminList\FilterType\DBAL;
4
5
use Symfony\Component\HttpFoundation\Request;
6
7
/**
8
 * NumberFilterType
9
 */
10 View Code Duplication
class NumberFilterType extends AbstractDBALFilterType
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
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 8
    public function apply(array $data, $uniqueId)
28
    {
29 8
        if (isset($data['value'], $data['comparator'])) {
30 8
            switch ($data['comparator']) {
31 8
                case 'eq':
32 1
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->eq($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
33
34 1
                    break;
35 7
                case 'neq':
36 1
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->neq($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
37
38 1
                    break;
39 6
                case 'lt':
40 1
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->lt($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
41
42 1
                    break;
43 5
                case 'lte':
44 1
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->lte($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
45
46 1
                    break;
47 4
                case 'gt':
48 1
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->gt($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
49
50 1
                    break;
51 3
                case 'gte':
52 1
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->gte($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
53
54 1
                    break;
55 2
                case 'isnull':
56 1
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->isNull($this->getAlias() . $this->columnName));
57
58 1
                    return;
59 1
                case 'isnotnull':
60 1
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->isNotNull($this->getAlias() . $this->columnName));
61
62 1
                    return;
63
            }
64 6
            $this->queryBuilder->setParameter('var_' . $uniqueId, $data['value']);
65
        }
66 6
    }
67
68
    /**
69
     * @return string
70
     */
71 1
    public function getTemplate()
72
    {
73 1
        return '@KunstmaanAdminList/FilterType/numberFilter.html.twig';
74
    }
75
}
76