Completed
Push — master ( 7d3672...a34d6f )
by Simonas
357:48 queued 292:56
created

AbstractRange   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 6
dl 0
loc 50
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setInclusive() 0 6 1
A isInclusive() 0 4 1
A createViewData() 0 4 1
A modifySearch() 0 7 3
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\FilterManagerBundle\Filter\Widget\Range;
13
14
use ONGR\ElasticsearchDSL\Filter\RangeFilter;
15
use ONGR\ElasticsearchDSL\Search;
16
use ONGR\FilterManagerBundle\Filter\FilterState;
17
use ONGR\FilterManagerBundle\Filter\Helper\FieldAwareInterface;
18
use ONGR\FilterManagerBundle\Filter\Helper\FieldAwareTrait;
19
use ONGR\FilterManagerBundle\Filter\Helper\ViewDataFactoryInterface;
20
use ONGR\FilterManagerBundle\Filter\ViewData\RangeAwareViewData;
21
use ONGR\FilterManagerBundle\Filter\Widget\AbstractSingleRequestValueFilter;
22
use ONGR\FilterManagerBundle\Search\SearchRequest;
23
24
/**
25
 * Class AbstractRangeFilter.
26
 */
27
abstract class AbstractRange extends AbstractSingleRequestValueFilter implements
28
    FieldAwareInterface,
29
    ViewDataFactoryInterface
30
{
31
    use FieldAwareTrait;
32
33
    /**
34
     * @var bool
35
     */
36
    private $inclusive = false;
37
38
    /**
39
     * @param bool $inclusive
40
     *
41
     * @return $this
42
     */
43
    public function setInclusive($inclusive)
44
    {
45
        $this->inclusive = $inclusive;
46
47
        return $this;
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    public function isInclusive()
54
    {
55
        return $this->inclusive;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function createViewData()
62
    {
63
        return new RangeAwareViewData();
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null)
70
    {
71
        if ($state && $state->isActive()) {
72
            $filter = new RangeFilter($this->getField(), $state->getValue());
73
            $search->addPostFilter($filter);
74
        }
75
    }
76
}
77