Completed
Push — master ( a8e426...cdcd92 )
by Simonas
62:46
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\TermLevel\RangeQuery;
15
use ONGR\ElasticsearchDSL\Search;
16
use ONGR\FilterManagerBundle\Filter\FilterState;
17
use ONGR\FilterManagerBundle\Filter\Helper\ViewDataFactoryInterface;
18
use ONGR\FilterManagerBundle\Filter\ViewData\RangeAwareViewData;
19
use ONGR\FilterManagerBundle\Filter\Widget\AbstractFilter;
20
use ONGR\FilterManagerBundle\Search\SearchRequest;
21
22
/**
23
 * Class AbstractRangeFilter.
24
 */
25
abstract class AbstractRange extends AbstractFilter implements ViewDataFactoryInterface
26
{
27
    /**
28
     * @return bool
29
     */
30
    public function isInclusive()
31
    {
32
        return $this->getOption('inclusive', false);
0 ignored issues
show
false is of type boolean, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function createViewData()
39
    {
40
        return new RangeAwareViewData();
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 View Code Duplication
    public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null)
47
    {
48
        if ($state && $state->isActive()) {
49
            $filter = new RangeQuery($this->getDocumentField(), $state->getValue());
50
            $search->addPostFilter($filter);
51
        }
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function isRelated()
58
    {
59
        return true;
60
    }
61
}
62