Completed
Push — master ( 6b6a70...d90581 )
by Simonas
02:43 queued 51s
created

NestedSort::getNestedFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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\Sort;
13
14
use ONGR\ElasticsearchDSL\BuilderInterface;
15
use ONGR\ElasticsearchDSL\ParametersTrait;
16
17
/**
18
 * Represents Elasticsearch "nested" sort filter.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/filter-dsl-nested-filter.html
21
 */
22
class NestedSort implements BuilderInterface
23
{
24
    use ParametersTrait;
25
26
    /**
27
     * @var string
28
     */
29
    private $path;
30
31
    /**
32
     * @var BuilderInterface
33
     */
34
    private $filter;
35
36
    /**
37
     * @var BuilderInterface
38
     */
39
    private $nestedFilter;
40
41
    /**
42
     * @param string $path
43
     * @param BuilderInterface $filter
44
     * @param array $parameters
45
     */
46
    public function __construct(
47
        $path,
48
        BuilderInterface $filter = null,
49
        array $parameters = []
50
    ) {
51
        $this->path = $path;
52
        $this->filter = $filter;
53
        $this->setParameters($parameters);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getType()
60
    {
61
        return 'nested';
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function toArray()
68
    {
69
        $output = [
70
            'path'   => $this->path,
71
        ];
72
73
        if ($this->filter) {
74
            $output['filter'] = $this->filter->toArray();
75
        }
76
77
        if ($this->nestedFilter) {
78
            $output[$this->getType()] = $this->nestedFilter->toArray();
79
        }
80
81
        return $this->processArray($output);
82
    }
83
84
    /**
85
     * Returns nested filter object.
86
     *
87
     * @return BuilderInterface
88
     */
89
    public function getFilter()
90
    {
91
        return $this->filter;
92
    }
93
94
    /**
95
     * Returns path this filter is set for.
96
     *
97
     * @return string
98
     */
99
    public function getPath()
100
    {
101
        return $this->path;
102
    }
103
104
    /**
105
     * @return BuilderInterface
106
     */
107
    public function getNestedFilter()
108
    {
109
        return $this->nestedFilter;
110
    }
111
112
    /**
113
     * @param BuilderInterface $nestedFilter
114
     */
115
    public function setNestedFilter(BuilderInterface $nestedFilter)
116
    {
117
        $this->nestedFilter = $nestedFilter;
118
    }
119
}
120