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

SpanMulti::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
namespace Elastica\Query;
3
4
use Elastica\Exception\InvalidException;
5
6
/**
7
 * SpanMulti query.
8
 *
9
 * @author Marek Hernik <[email protected]>
10
 * @author Alessandro Chitolina <[email protected]>
11
 *
12
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-multi-term-query.html
13
 */
14
class SpanMulti extends AbstractSpanQuery
15
{
16
    /**
17
     * Constructs a SpanMulti query object.
18
     *
19
     * @param \Elastica\Query\AbstractQuery|array $match OPTIONAL
20
     */
21
    public function __construct($match = null)
22
    {
23
        if (null !== $match) {
24
            $this->setMatch($match);
25
        }
26
    }
27
28
    /**
29
     * Set the query to be wrapped into the span multi query.
30
     *
31
     * @param \Elastica\Query\AbstractQuery|array $args Matching query
32
     *
33
     * @return $this
34
     */
35
    public function setMatch($args)
36
    {
37
        return $this->_setQuery('match', $args);
38
    }
39
40
    /**
41
     * Sets a query to the current object.
42
     *
43
     * @param string                              $type Query type
44
     * @param \Elastica\Query\AbstractQuery|array $args Query
45
     *
46
     * @throws \Elastica\Exception\InvalidException If not valid query
47
     *
48
     * @return $this
49
     */
50 View Code Duplication
    protected function _setQuery($type, $args)
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...
51
    {
52
        if (!is_array($args) && !($args instanceof AbstractQuery)) {
53
            throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery');
54
        }
55
56
        return $this->setParam($type, $args);
57
    }
58
}
59