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 | * Bool query. |
||
8 | * |
||
9 | * @author Nicolas Ruflin <[email protected]> |
||
10 | * |
||
11 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html |
||
12 | */ |
||
13 | class BoolQuery extends AbstractQuery |
||
14 | { |
||
15 | /** |
||
16 | * Add should part to query. |
||
17 | * |
||
18 | * @param \Elastica\Query\AbstractQuery|array $args Should query |
||
19 | * |
||
20 | * @return $this |
||
21 | */ |
||
22 | public function addShould($args) |
||
23 | { |
||
24 | return $this->_addQuery('should', $args); |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Add must part to query. |
||
29 | * |
||
30 | * @param \Elastica\Query\AbstractQuery|array $args Must query |
||
31 | * |
||
32 | * @return $this |
||
33 | */ |
||
34 | public function addMust($args) |
||
35 | { |
||
36 | return $this->_addQuery('must', $args); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Add must not part to query. |
||
41 | * |
||
42 | * @param \Elastica\Query\AbstractQuery|array $args Must not query |
||
43 | * |
||
44 | * @return $this |
||
45 | */ |
||
46 | public function addMustNot($args) |
||
47 | { |
||
48 | return $this->_addQuery('must_not', $args); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Sets the filter. |
||
53 | * |
||
54 | * @param \Elastica\Query\AbstractQuery $filter Filter object |
||
55 | * |
||
56 | * @return $this |
||
57 | */ |
||
58 | public function addFilter(AbstractQuery $filter) |
||
59 | { |
||
60 | return $this->addParam('filter', $filter); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Adds a query to the current object. |
||
65 | * |
||
66 | * @param string $type Query type |
||
67 | * @param \Elastica\Query\AbstractQuery|array $args Query |
||
68 | * |
||
69 | * @throws \Elastica\Exception\InvalidException If not valid query |
||
70 | * |
||
71 | * @return $this |
||
72 | */ |
||
73 | View Code Duplication | protected function _addQuery($type, $args) |
|
74 | { |
||
75 | if (!is_array($args) && !($args instanceof AbstractQuery)) { |
||
76 | throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery'); |
||
77 | } |
||
78 | |||
79 | return $this->addParam($type, $args); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Sets boost value of this query. |
||
84 | * |
||
85 | * @param float $boost Boost value |
||
86 | * |
||
87 | * @return $this |
||
88 | */ |
||
89 | public function setBoost($boost) |
||
90 | { |
||
91 | return $this->setParam('boost', $boost); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Set the minimum number of of should match. |
||
96 | * |
||
97 | * @param int $minimumNumberShouldMatch Should match minimum |
||
98 | * |
||
99 | * @return $this |
||
100 | */ |
||
101 | public function setMinimumNumberShouldMatch($minimumNumberShouldMatch) |
||
102 | { |
||
103 | return $this->setParam('minimum_number_should_match', $minimumNumberShouldMatch); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Converts array to an object in case no queries are added. |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | public function toArray() |
||
112 | { |
||
113 | if (empty($this->_params)) { |
||
114 | $this->_params = new \stdClass(); |
||
0 ignored issues
–
show
|
|||
115 | } |
||
116 | |||
117 | return parent::toArray(); |
||
118 | } |
||
119 | } |
||
120 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..