Completed
Pull Request — develop (#25)
by Sam
03:27 queued 34s
created

NestedQuery::setQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php namespace Nord\Lumen\Elasticsearch\Search\Query\Joining;
2
3
use Nord\Lumen\Elasticsearch\Search\Query\ScoreMode;
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
    /**
22
     * @inheritdoc
23
     */
24 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...
25
    {
26
        $nested = [
27
            'path'  => $this->getPath(),
28
            'query' => $this->getQuery()->toArray(),
29
        ];
30
31
        $scoreMode = $this->getScoreMode();
32
        if (!is_null($scoreMode)) {
33
            $nested['score_mode'] = $scoreMode;
34
        }
35
36
        return ['nested' => $nested];
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 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...
43
    {
44
        return [
45
            ScoreMode::MODE_AVG,
46
            ScoreMode::MODE_SUM,
47
            ScoreMode::MODE_MIN,
48
            ScoreMode::MODE_MAX,
49
            ScoreMode::MODE_NONE,
50
        ];
51
    }
52
53
54
    /**
55
     * @param string $path
56
     * @return NestedQuery
57
     */
58
    public function setPath($path)
59
    {
60
        $this->path = $path;
61
        return $this;
62
    }
63
64
65
    /**
66
     * @return string
67
     */
68
    public function getPath()
69
    {
70
        return $this->path;
71
    }
72
}
73