Completed
Pull Request — master (#1876)
by romain
02:52
created

Percentiles   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 74
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A setCompression() 0 6 1
A setHdr() 0 6 1
A setPercents() 0 4 1
A addPercent() 0 4 1
A setMissing() 0 4 1
1
<?php
2
3
namespace Elastica\Aggregation;
4
5
/**
6
 * Class Percentiles.
7
 *
8
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html
9
 */
10
class Percentiles extends AbstractSimpleAggregation
11
{
12
    use KeyedTrait;
13
14
    /**
15
     * @param string $name  the name of this aggregation
16
     * @param string $field the field on which to perform this aggregation
17
     */
18
    public function __construct(string $name, ?string $field = null)
19
    {
20
        parent::__construct($name);
21
22
        if (null !== $field) {
23
            $this->setField($field);
24
        }
25
    }
26
27
    /**
28
     * Set compression parameter.
29
     *
30
     * @return $this
31
     */
32
    public function setCompression(float $value): self
33
    {
34
        $compression = ['compression' => $value];
35
36
        return $this->setParam('tdigest', $compression);
37
    }
38
39
    /**
40
     * Set hdr parameter.
41
     *
42
     * @return $this
43
     */
44
    public function setHdr(string $key, float $value): self
45
    {
46
        $compression = [$key => $value];
47
48
        return $this->setParam('hdr', $compression);
49
    }
50
51
    /**
52
     * Set which percents must be returned.
53
     *
54
     * @param float[] $percents
55
     *
56
     * @return $this
57
     */
58
    public function setPercents(array $percents): self
59
    {
60
        return $this->setParam('percents', $percents);
61
    }
62
63
    /**
64
     * Add yet another percent to result.
65
     *
66
     * @return $this
67
     */
68
    public function addPercent(float $percent): self
69
    {
70
        return $this->addParam('percents', $percent);
71
    }
72
73
    /**
74
     * Defines how documents that are missing a value should
75
     * be treated.
76
     *
77
     * @return $this
78
     */
79
    public function setMissing(float $missing): self
80
    {
81
        return $this->setParam('missing', $missing);
82
    }
83
}
84