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

HasParentQuery::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\QueryDSL;
4
5
/**
6
 * The has_parent query accepts a query and a parent type. The query is executed in the parent document space, which is
7
 * specified by the parent type. This query returns child documents which associated parents have matched. For the rest
8
 * has_parent query has the same options and works in the same manner as the has_child query.
9
 *
10
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html
11
 */
12
class HasParentQuery extends AbstractQuery
13
{
14
15
    /**
16
     * @var string
17
     */
18
    private $type;
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
        $hasParent = [
32
            'parent_type'  => $this->getType(),
33
            'query'        => $this->getQuery()->toArray(),
34
        ];
35
36
        $scoreMode = $this->getScoreMode();
37
        if (!is_null($scoreMode)) {
38
            $hasParent['score_mode'] = $scoreMode;
39
        }
40
41
        return ['has_parent' => $hasParent];
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    protected function getValidScoreModes()
48
    {
49
        return [
50
            self::SCORE_MODE_SCORE,
51
            self::SCORE_MODE_NONE
52
        ];
53
    }
54
55
    /**
56
     * @param string $type
57
     * @return HasParentQuery
58
     */
59
    public function setType($type)
60
    {
61
        $this->type = $type;
62
        return $this;
63
    }
64
65
66
    /**
67
     * @return string
68
     */
69
    public function getType()
70
    {
71
        return $this->type;
72
    }
73
74
75
    /**
76
     * @param QueryDSL $query
77
     * @return HasParentQuery
78
     */
79
    public function setQuery(QueryDSL $query)
80
    {
81
        $this->query = $query;
82
        return $this;
83
    }
84
85
86
    /**
87
     * @return QueryDSL
88
     */
89
    public function getQuery()
90
    {
91
        return $this->query;
92
    }
93
}
94