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

SpanMulti   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 17.78 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 8
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A setMatch() 0 4 1
A _setQuery() 8 8 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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