DateFilter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 45
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFieldType() 0 4 1
A applyTypeIsLessEqual() 0 6 1
A applyTypeIsGreaterThan() 0 6 1
A applyTypeIsEqual() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrineMongoDBAdminBundle\Filter;
15
16
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
17
use Symfony\Component\Form\Extension\Core\Type\DateType;
18
19
class DateFilter extends AbstractDateFilter
20
{
21
    public function getFieldType(): string
22
    {
23
        return $this->getOption('field_type', DateType::class);
24
    }
25
26
    /**
27
     * @param string $field
28
     * @param array  $data
29
     */
30
    protected function applyTypeIsLessEqual(ProxyQueryInterface $queryBuilder, $field, $data): void
31
    {
32
        $data['value']->add(new \DateInterval('P1D'));
33
34
        $this->applyType($queryBuilder, $this->getOperator($data['type']), $field, $data['value']);
35
    }
36
37
    /**
38
     * @param string $field
39
     * @param array  $data
40
     */
41
    protected function applyTypeIsGreaterThan(ProxyQueryInterface $queryBuilder, $field, $data): void
42
    {
43
        $data['value']->add(new \DateInterval('P1D'));
44
45
        $this->applyType($queryBuilder, $this->getOperator($data['type']), $field, $data['value']);
46
    }
47
48
    /**
49
     * Because we lack a time variable we select a range from the days start to end.
50
     *
51
     * @author Wesley van Opdorp <[email protected]>
52
     *
53
     * @param string $field
54
     * @param array  $data
55
     */
56
    protected function applyTypeIsEqual(ProxyQueryInterface $queryBuilder, $field, $data): void
57
    {
58
        $end = clone $data['value'];
59
        $end->add(new \DateInterval('P1D'));
60
61
        $queryBuilder->field($field)->range($data['value'], $end);
62
    }
63
}
64