Completed
Push — master ( c427a2...065b11 )
by Nicolas
02:23
created

AvgBucket::setGapPolicy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Elastica\Aggregation;
3
4
use Elastica\Exception\InvalidException;
5
6
/**
7
 * Class AvgBucket.
8
 *
9
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html
10
 */
11 View Code Duplication
class AvgBucket extends AbstractAggregation
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /**
14
     * @param string      $name
15
     * @param string|null  $bucketsPath
16
     */
17
    public function __construct($name, $bucketsPath = null)
18
    {
19
        parent::__construct($name);
20
21
        if ($bucketsPath !== null) {
22
            $this->setBucketsPath($bucketsPath);
23
        }
24
    }
25
26
    /**
27
     * Set the buckets_path for this aggregation.
28
     *
29
     * @param string $bucketsPath
30
     *
31
     * @return $this
32
     */
33
    public function setBucketsPath($bucketsPath)
34
    {
35
        return $this->setParam('buckets_path', $bucketsPath);
36
    }
37
38
    /**
39
     * Set the gap policy for this aggregation.
40
     *
41
     * @param string $gapPolicy
42
     *
43
     * @return $this
44
     */
45
    public function setGapPolicy($gapPolicy)
46
    {
47
        return $this->setParam('gap_policy', $gapPolicy);
48
    }
49
50
    /**
51
     * Set the format for this aggregation.
52
     *
53
     * @param string $format
54
     *
55
     * @return $this
56
     */
57
    public function setFormat($format)
58
    {
59
        return $this->setParam('format', $format);
60
    }
61
62
    /**
63
     * @throws InvalidException If buckets path or script is not set
64
     *
65
     * @return array
66
     */
67
    public function toArray()
68
    {
69
        if (!$this->hasParam('buckets_path')) {
70
            throw new InvalidException('Buckets path is required');
71
        }
72
73
        return parent::toArray();
74
    }
75
}
76