Completed
Pull Request — master (#267)
by
unknown
15:04
created

NestedSort::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 7
nc 1
nop 3
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,
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
            'filter' => $this->filter->toArray(),
72
        ];
73
74
        if ($this->nestedFilter) {
75
            $output[$this->getType()] = $this->nestedFilter->toArray();
76
        }
77
78
        return $this->processArray($output);
79
    }
80
81
    /**
82
     * Returns nested filter object.
83
     *
84
     * @return BuilderInterface
85
     */
86
    public function getFilter()
87
    {
88
        return $this->filter;
89
    }
90
91
    /**
92
     * Returns path this filter is set for.
93
     *
94
     * @return string
95
     */
96
    public function getPath()
97
    {
98
        return $this->path;
99
    }
100
101
    /**
102
     * @return BuilderInterface
103
     */
104
    public function getNestedFilter()
105
    {
106
        return $this->nestedFilter;
107
    }
108
109
    /**
110
     * @param BuilderInterface $nestedFilter
111
     */
112
    public function setNestedFilter(BuilderInterface $nestedFilter)
113
    {
114
        $this->nestedFilter = $nestedFilter;
115
    }
116
}
117