Completed
Push — master ( 4059cd...ef58c8 )
by Simonas
84:03 queued 19:25
created

Filter/Widget/Range/AbstractRange.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Query\RangeQuery;
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 View Code Duplication
    public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null)
0 ignored issues
show
This method 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...
70
    {
71
        if ($state && $state->isActive()) {
72
            $filter = new RangeQuery($this->getField(), $state->getValue());
73
            $search->addPostFilter($filter);
74
        }
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function isRelated()
81
    {
82
        return false;
83
    }
84
}
85