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

SpanOr::__construct()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 9
Ratio 69.23 %

Importance

Changes 0
Metric Value
dl 9
loc 13
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 3
nop 1
1
<?php
2
namespace Elastica\Query;
3
4
use Elastica\Exception\InvalidException;
5
6
/**
7
 * SpanOr query.
8
 *
9
 * @author Marek Hernik <[email protected]>
10
 *
11
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-term-query.html
12
 */
13
class SpanOr extends AbstractSpanQuery
14
{
15
    /**
16
     * Constructs a SpanOr query object.
17
     *
18
     * @param AbstractSpanQuery[] $clauses OPTIONAL
19
     */
20
    public function __construct($clauses = [])
21
    {
22 View Code Duplication
        if (!empty($clauses)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
23
            foreach ($clauses as $clause) {
24
                if (!is_subclass_of($clause, AbstractSpanQuery::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Elastica\Query\AbstractSpanQuery::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
25
                    throw new InvalidException(
26
                        'Invalid parameter. Has to be array or instance of Elastica\Query\SpanQuery'
27
                    );
28
                }
29
            }
30
        }
31
        $this->setParams(['clauses' => $clauses]);
32
    }
33
34
    /**
35
     * Add clause part to query.
36
     *
37
     * @param AbstractSpanQuery $clause
38
     *
39
     * @throws InvalidException If not valid query
40
     *
41
     * @return $this
42
     */
43 View Code Duplication
    public function addClause($clause)
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...
44
    {
45
        if (!is_subclass_of($clause, AbstractSpanQuery::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Elastica\Query\AbstractSpanQuery::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
46
            throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\SpanQuery');
47
        }
48
49
        return $this->addParam('clauses', $clause);
50
    }
51
}