Completed
Push — master ( 4cdb71...eee063 )
by Nicolas
02:28
created

lib/Elastica/Query/ConstantScore.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
namespace Elastica\Query;
3
4
use Elastica\Exception\InvalidException;
5
6
/**
7
 * Constant score query.
8
 *
9
 * @author Nicolas Ruflin <[email protected]>
10
 *
11
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html
12
 */
13
class ConstantScore extends AbstractQuery
14
{
15
    /**
16
     * Construct constant score query.
17
     *
18
     * @param null|AbstractQuery|array $filter
19
     */
20
    public function __construct(AbstractQuery $filter = null)
21
    {
22
        if (!is_null($filter)) {
23
            $this->setFilter($filter);
24
        }
25
    }
26
27
    /**
28
     * Set filter.
29
     *
30
     * @param array|AbstractQuery $filter
31
     *
32
     * @return $this
33
     */
34
    public function setFilter(AbstractQuery $filter)
35
    {
36
        return $this->setParam('filter', $filter);
37
    }
38
39
    /**
40
     * Set query.
41
     *
42
     * @param array|AbstractQuery $query
43
     *
44
     * @throws InvalidException If query is not an array or instance of AbstractQuery
45
     *
46
     * @return $this
47
     */
48 View Code Duplication
    public function setQuery($query)
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...
49
    {
50
        if (!is_array($query) && !($query instanceof AbstractQuery)) {
51
            throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery');
52
        }
53
54
        return $this->setParam('query', $query);
55
    }
56
57
    /**
58
     * Set boost.
59
     *
60
     * @param float $boost
61
     *
62
     * @return $this
63
     */
64
    public function setBoost($boost)
65
    {
66
        return $this->setParam('boost', $boost);
67
    }
68
}
69