Completed
Pull Request — master (#129)
by
unknown
02:49
created

AvgBucketAggregation::setBucketsPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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\Pipeline;
13
14
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
15
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait;
16
17
/**
18
 * Class representing Avg Bucket Pipeline Aggregation.
19
 *
20
 * @link https://goo.gl/SWK2nP
21
 */
22
class AvgBucketAggregation extends AbstractAggregation
23
{
24
    use MetricTrait;
25
26
    /**
27
     * @var string
28
     */
29
    private $bucketsPath;
30
31
    /**
32
     * @param string $name
33
     * @param $bucketsPath
34
     */
35
    public function __construct($name, $bucketsPath = null)
36
    {
37
        parent::__construct($name);
38
39
        if ($bucketsPath) {
40
            $this->setBucketsPath($bucketsPath);
41
        }
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getBucketsPath()
48
    {
49
        return $this->bucketsPath;
50
    }
51
52
    /**
53
     * @param string $bucketsPath
54
     */
55
    public function setBucketsPath($bucketsPath)
56
    {
57
        $this->bucketsPath = $bucketsPath;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getType()
64
    {
65
        return 'avg_bucket';
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getArray()
72
    {
73
        if (!$this->getBucketsPath()) {
74
            throw new \LogicException('Avg bucket aggregation must have buckets_field set.');
75
        }
76
77
        return ['buckets_path' => $this->getBucketsPath()];
78
    }
79
}
80