Completed
Pull Request — master (#148)
by Simonas
05:22
created

ReverseNestedAggregation::getArray()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 3
eloc 7
nc 3
nop 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\Aggregation\Bucketing;
13
14
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
15
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;
16
17
/**
18
 * Class representing ReverseNestedAggregation.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html
21
 */
22
class ReverseNestedAggregation extends AbstractAggregation
23
{
24
    use BucketingTrait;
25
26
    /**
27
     * @var string
28
     */
29
    private $path;
30
31
    /**
32
     * Inner aggregations container init.
33
     *
34
     * @param string $name
35
     * @param string $path
36
     */
37
    public function __construct($name, $path = null)
38
    {
39
        parent::__construct($name);
40
41
        $this->setPath($path);
42
    }
43
44
    /**
45
     * Return path.
46
     *
47
     * @return string
48
     */
49
    public function getPath()
50
    {
51
        return $this->path;
52
    }
53
54
    /**
55
     * Sets path.
56
     *
57
     * @param string $path
58
     */
59
    public function setPath($path)
60
    {
61
        $this->path = $path;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getType()
68
    {
69
        return 'reverse_nested';
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getArray()
76
    {
77
        if (count($this->getAggregations()) == 0) {
78
            throw new \LogicException("Reverse Nested aggregation `{$this->getName()}` has no aggregations added");
79
        }
80
81
        $output = new \stdClass();
82
        if ($this->getPath()) {
83
            $output = ['path' => $this->getPath()];
84
        }
85
86
        return $output;
87
    }
88
}
89