Completed
Push — master ( a8e426...cdcd92 )
by Simonas
62:46
created

AbstractRange::modifySearch()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 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\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
Documentation introduced by
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)
0 ignored issues
show
Duplication introduced by
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...
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