Completed
Push — master ( cdf882...92ebd2 )
by Nicolas
02:36
created

PercentilesBucket::setPercents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Elastica\Aggregation;
4
5
use Elastica\Exception\InvalidException;
6
7
/**
8
 * Class PercentilesBucket.
9
 *
10
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-percentiles-bucket-aggregation.html
11
 */
12
class PercentilesBucket extends AbstractAggregation
13
{
14
    /**
15
     * @param string      $name        the name of this aggregation
16
     * @param string|null $bucketsPath the field on which to perform this aggregation
17
     */
18
    public function __construct(string $name, ?string $bucketsPath = null)
19
    {
20
        parent::__construct($name);
21
22
        if (null !== $bucketsPath) {
23
            $this->setBucketsPath($bucketsPath);
24
        }
25
    }
26
27
    /**
28
     * @throws InvalidException If buckets path or script is not set
29
     */
30
    public function toArray(): array
31
    {
32
        if (!$this->hasParam('buckets_path')) {
33
            throw new InvalidException('Buckets path is required');
34
        }
35
36
        return parent::toArray();
37
    }
38
39
    /**
40
     * Set the buckets_path for this aggregation.
41
     */
42
    public function setBucketsPath(string $bucketsPath): self
43
    {
44
        return $this->setParam('buckets_path', $bucketsPath);
45
    }
46
47
    /**
48
     * Set the gap policy for this aggregation.
49
     */
50
    public function setGapPolicy(string $gapPolicy): self
51
    {
52
        return $this->setParam('gap_policy', $gapPolicy);
53
    }
54
55
    /**
56
     * Set the format for this aggregation.
57
     */
58
    public function setFormat(string $format): self
59
    {
60
        return $this->setParam('format', $format);
61
    }
62
63
    /**
64
     * Set which percents must be returned.
65
     *
66
     * @param float[] $percents
67
     */
68
    public function setPercents(array $percents): self
69
    {
70
        return $this->setParam('percents', $percents);
71
    }
72
73
    /**
74
     * Set keyed flag to return the range as an hash instead of an array of key-value pairs.
75
     */
76
    public function setKeyed(bool $keyed): self
77
    {
78
        return $this->setParam('keyed', $keyed);
79
    }
80
}
81