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

SpanFirst::setMatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Elastica\Query;
3
4
use Elastica\Exception\InvalidException;
5
6
/**
7
 * SpanFirst query.
8
 *
9
 * @author Alessandro Chitolina <[email protected]>
10
 *
11
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html
12
 */
13
class SpanFirst extends AbstractSpanQuery
14
{
15
    /**
16
     * Constructs a SpanFirst query object.
17
     *
18
     * @param \Elastica\Query\AbstractQuery|array $match OPTIONAL
19
     * @param int $end OPTIONAL
20
     */
21
    public function __construct($match = null, $end = null)
22
    {
23
        if (!is_null($match)) {
24
            $this->setMatch($match);
0 ignored issues
show
Bug introduced by
It seems like $match defined by parameter $match on line 21 can also be of type object<Elastica\Query\AbstractQuery>; however, Elastica\Query\SpanFirst::setMatch() does only seem to accept object<Elastica\Query\AbstractSpanQuery>|array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
25
        }
26
27
        if (!is_null($match)) {
28
            $this->setEnd($end);
29
        }
30
    }
31
32
    /**
33
     * Set the query to be wrapped into the span multi query.
34
     *
35
     * @param \Elastica\Query\AbstractSpanQuery|array $args Matching query
36
     *
37
     * @throws \Elastica\Exception\InvalidException If not valid query
38
     *
39
     * @return $this
40
     */
41
    public function setMatch($args)
42
    {
43
        return $this->_setQuery('match', $args);
44
    }
45
46
    /**
47
     * Set the maximum end position for the match query.
48
     *
49
     * @param int $end
50
     *
51
     * @return $this
52
     */
53
    public function setEnd($end)
54
    {
55
        $this->setParam('end', $end);
56
57
        return $this;
58
    }
59
60
    /**
61
     * Sets a query to the current object.
62
     *
63
     * @param string                              $type Query type
64
     * @param \Elastica\Query\AbstractQuery|array $args Query
65
     *
66
     * @throws \Elastica\Exception\InvalidException If not valid query
67
     *
68
     * @return $this
69
     */
70
    protected function _setQuery($type, $args)
71
    {
72
        if (!is_array($args) && !($args instanceof AbstractSpanQuery)) {
73
            throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractSpanQuery');
74
        }
75
76
        return $this->setParam($type, $args);
77
    }
78
}
79