SpanOrQuery   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A addQuery() 6 6 1
A getQueries() 4 4 1
A getType() 4 4 1
A toArray() 10 10 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
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchDSL\Query\Span;
13
14
use ONGR\ElasticsearchDSL\ParametersTrait;
15
16
/**
17
 * Elasticsearch span or query.
18
 *
19
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-or-query.html
20
 */
21 View Code Duplication
class SpanOrQuery implements SpanQueryInterface
0 ignored issues
show
Duplication introduced by
This class 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...
22
{
23
    use ParametersTrait;
24
25
    /**
26
     * @var SpanQueryInterface[]
27
     */
28
    private $queries = [];
29
30
    /**
31
     * @param array $parameters
32
     */
33
    public function __construct(array $parameters = [])
34
    {
35
        $this->setParameters($parameters);
36
    }
37
38
    /**
39
     * Add span query.
40
     *
41
     * @param SpanQueryInterface $query
42
     *
43
     * @return $this
44
     */
45
    public function addQuery(SpanQueryInterface $query)
46
    {
47
        $this->queries[] = $query;
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return SpanQueryInterface[]
54
     */
55
    public function getQueries()
56
    {
57
        return $this->queries;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getType()
64
    {
65
        return 'span_or';
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function toArray()
72
    {
73
        $query = [];
74
        foreach ($this->queries as $type) {
75
            $query['clauses'][] = $type->toArray();
76
        }
77
        $output = $this->processArray($query);
78
79
        return [$this->getType() => $output];
80
    }
81
}
82