Code Duplication    Length = 66-66 lines in 2 locations

src/Kunstmaan/AdminListBundle/AdminList/FilterType/DBAL/NumberFilterType.php 1 location

@@ 10-75 (lines=66) @@
7
/**
8
 * NumberFilterType
9
 */
10
class NumberFilterType extends AbstractDBALFilterType
11
{
12
    /**
13
     * @param Request $request  The request
14
     * @param array   &$data    The data
15
     * @param string  $uniqueId The unique identifier
16
     */
17
    public function bindRequest(Request $request, array &$data, $uniqueId)
18
    {
19
        $data['comparator'] = $request->query->get('filter_comparator_' . $uniqueId);
20
        $data['value'] = $request->query->get('filter_value_' . $uniqueId);
21
    }
22
23
    /**
24
     * @param array  $data     The data
25
     * @param string $uniqueId The unique identifier
26
     */
27
    public function apply(array $data, $uniqueId)
28
    {
29
        if (isset($data['value'], $data['comparator'])) {
30
            switch ($data['comparator']) {
31
                case 'eq':
32
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->eq($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
33
34
                    break;
35
                case 'neq':
36
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->neq($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
37
38
                    break;
39
                case 'lt':
40
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->lt($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
41
42
                    break;
43
                case 'lte':
44
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->lte($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
45
46
                    break;
47
                case 'gt':
48
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->gt($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
49
50
                    break;
51
                case 'gte':
52
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->gte($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
53
54
                    break;
55
                case 'isnull':
56
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->isNull($this->getAlias() . $this->columnName));
57
58
                    return;
59
                case 'isnotnull':
60
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->isNotNull($this->getAlias() . $this->columnName));
61
62
                    return;
63
            }
64
            $this->queryBuilder->setParameter('var_' . $uniqueId, $data['value']);
65
        }
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getTemplate()
72
    {
73
        return '@KunstmaanAdminList/FilterType/numberFilter.html.twig';
74
    }
75
}
76

src/Kunstmaan/AdminListBundle/AdminList/FilterType/ORM/NumberFilterType.php 1 location

@@ 10-75 (lines=66) @@
7
/**
8
 * NumberFilterType
9
 */
10
class NumberFilterType 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
    public function bindRequest(Request $request, array &$data, $uniqueId)
18
    {
19
        $data['comparator'] = $request->query->get('filter_comparator_' . $uniqueId);
20
        $data['value'] = $request->query->get('filter_value_' . $uniqueId);
21
    }
22
23
    /**
24
     * @param array  $data     The data
25
     * @param string $uniqueId The unique identifier
26
     */
27
    public function apply(array $data, $uniqueId)
28
    {
29
        if (isset($data['value'], $data['comparator'])) {
30
            switch ($data['comparator']) {
31
                case 'eq':
32
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->eq($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
33
34
                    break;
35
                case 'neq':
36
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->neq($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
37
38
                    break;
39
                case 'lt':
40
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->lt($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
41
42
                    break;
43
                case 'lte':
44
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->lte($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
45
46
                    break;
47
                case 'gt':
48
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->gt($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
49
50
                    break;
51
                case 'gte':
52
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->gte($this->getAlias() . $this->columnName, ':var_' . $uniqueId));
53
54
                    break;
55
                case 'isnull':
56
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->isNull($this->getAlias() . $this->columnName));
57
58
                    return;
59
                case 'isnotnull':
60
                    $this->queryBuilder->andWhere($this->queryBuilder->expr()->isNotNull($this->getAlias() . $this->columnName));
61
62
                    return;
63
            }
64
            $this->queryBuilder->setParameter('var_' . $uniqueId, $data['value']);
65
        }
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getTemplate()
72
    {
73
        return '@KunstmaanAdminList/FilterType/numberFilter.html.twig';
74
    }
75
}
76