Completed
Pull Request — master (#348)
by
unknown
10:14
created

NestedSort   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 102
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
declare(strict_types=1);
13
14
namespace ONGR\ElasticsearchDSL\Sort;
15
16
use ONGR\ElasticsearchDSL\BuilderInterface;
17
use ONGR\ElasticsearchDSL\ParametersTrait;
18
19
/**
20
 * Represents Elasticsearch "nested" sort filter.
21
 *
22
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/filter-dsl-nested-filter.html
23
 */
24
class NestedSort implements BuilderInterface
25
{
26
    use ParametersTrait;
27
28
    private ?BuilderInterface $nestedFilter = null;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?', expecting T_FUNCTION or T_CONST
Loading history...
29
30
    public function __construct(
31
        private string $path,
32
        private ?BuilderInterface $filter = null,
33
        array $parameters = []
34
    ) {
35
        $this->setParameters($parameters);
36
    }
37
38
    public function getType(): string
39
    {
40
        return 'nested';
41
    }
42
43
    public function toArray(): array
44
    {
45
        $output = [
46
            'path' => $this->path,
47
        ];
48
49
        if ($this->filter) {
50
            $output['filter'] = $this->filter->toArray();
51
        }
52
53
        if ($this->nestedFilter) {
54
            $output[$this->getType()] = $this->nestedFilter->toArray();
55
        }
56
57
        return $this->processArray($output);
58
    }
59
60
    public function getFilter(): ?BuilderInterface
61
    {
62
        return $this->filter;
63
    }
64
65
    public function getPath(): string
66
    {
67
        return $this->path;
68
    }
69
70
    public function getNestedFilter(): ?BuilderInterface
71
    {
72
        return $this->nestedFilter;
73
    }
74
75
    public function setNestedFilter(?BuilderInterface $nestedFilter): static
76
    {
77
        $this->nestedFilter = $nestedFilter;
78
79
        return $this;
80
    }
81
}
82