Completed
Pull Request — develop (#22)
by Sam
02:00
created

NestedQuery::toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Nord\Lumen\Elasticsearch\Search\Query\Joining;
2
3
use Nord\Lumen\Elasticsearch\Search\Query\QueryDSL;
4
5
/**
6
 * Nested query allows to query nested objects / docs (see nested mapping).
7
 *
8
 * The query is executed against the nested objects / docs as if they were indexed as separate docs (they are,
9
 * internally) and resulting in the root parent doc (or parent nested mapping).
10
 *
11
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html
12
 */
13
class NestedQuery extends AbstractQuery
14
{
15
    /**
16
     * @var string
17
     */
18
    private $path;
19
20
    /**
21
     * @var QueryDSL
22
     */
23
    private $query;
24
25
26
    /**
27
     * @inheritdoc
28
     */
29 View Code Duplication
    public function toArray()
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...
30
    {
31
        $nested = [
32
            'path'  => $this->getPath(),
33
            'query' => $this->getQuery()->toArray(),
34
        ];
35
36
        $scoreMode = $this->getScoreMode();
37
        if (!is_null($scoreMode)) {
38
            $nested['score_mode'] = $scoreMode;
39
        }
40
41
        return ['nested' => $nested];
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47 View Code Duplication
    protected function getValidScoreModes()
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...
48
    {
49
        return [
50
            self::SCORE_MODE_AVG,
51
            self::SCORE_MODE_SUM,
52
            self::SCORE_MODE_MIN,
53
            self::SCORE_MODE_MAX,
54
            self::SCORE_MODE_NONE,
55
        ];
56
    }
57
58
59
    /**
60
     * @param string $path
61
     * @return NestedQuery
62
     */
63
    public function setPath($path)
64
    {
65
        $this->path = $path;
66
        return $this;
67
    }
68
69
70
    /**
71
     * @return string
72
     */
73
    public function getPath()
74
    {
75
        return $this->path;
76
    }
77
78
79
    /**
80
     * @param QueryDSL $query
81
     * @return NestedQuery
82
     */
83
    public function setQuery(QueryDSL $query)
84
    {
85
        $this->query = $query;
86
        return $this;
87
    }
88
89
90
    /**
91
     * @return QueryDSL
92
     */
93
    public function getQuery()
94
    {
95
        return $this->query;
96
    }
97
}
98