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

SpanOr   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 43.59 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 13 4
A addClause() 8 8 2

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
 * 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
}