DisMaxQuery::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Compound;
13
14
use ONGR\ElasticsearchDSL\BuilderInterface;
15
use ONGR\ElasticsearchDSL\ParametersTrait;
16
17
/**
18
 * Represents Elasticsearch "dis_max" query.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html
21
 */
22 View Code Duplication
class DisMaxQuery implements BuilderInterface
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...
23
{
24
    use ParametersTrait;
25
26
    /**
27
     * @var BuilderInterface[]
28
     */
29
    private $queries = [];
30
31
    /**
32
     * Initializes Dis Max query.
33
     *
34
     * @param array $parameters
35
     */
36
    public function __construct(array $parameters = [])
37
    {
38
        $this->setParameters($parameters);
39
    }
40
41
    /**
42
     * Add query.
43
     *
44
     * @param BuilderInterface $query
45
     *
46
     * @return DisMaxQuery
47
     */
48
    public function addQuery(BuilderInterface $query)
49
    {
50
        $this->queries[] = $query;
51
52
        return $this;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getType()
59
    {
60
        return 'dis_max';
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function toArray()
67
    {
68
        $query = [];
69
        foreach ($this->queries as $type) {
70
            $query[] = $type->toArray();
71
        }
72
        $output = $this->processArray(['queries' => $query]);
73
74
        return [$this->getType() => $output];
75
    }
76
}
77