Completed
Pull Request — master (#348)
by
unknown
09:42 queued 08:20
created

ExtendedStatsAggregation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 74
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ONGR\ElasticsearchDSL\Aggregation\Metric;
4
5
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
6
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait;
7
use ONGR\ElasticsearchDSL\ScriptAwareTrait;
8
9
/**
10
 * Class representing Extended stats aggregation.
11
 *
12
 * @link http://goo.gl/E0PpDv
13
 */
14
class ExtendedStatsAggregation extends AbstractAggregation
15
{
16
    use MetricTrait;
17
18
    use ScriptAwareTrait;
19
20
    public function __construct(
21
        private string $name,
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_PRIVATE, expecting T_VARIABLE
Loading history...
22
        private ?string $field = null,
23
        private ?int $sigma = null,
24
        private ?string $script = null
25
    ) {
26
        parent::__construct($name);
27
28
        $this->setField($field);
29
    }
30
31
    public function getSigma(): ?int
32
    {
33
        return $this->sigma;
34
    }
35
36
    public function setSigma(?int $sigma): static
37
    {
38
        $this->sigma = $sigma;
39
40
        return $this;
41
    }
42
43
    public function getType(): string
44
    {
45
        return 'extended_stats';
46
    }
47
48
    public function getArray(): array
49
    {
50
        return array_filter(
51
            [
52
                'field' => $this->getField(),
53
                'script' => $this->getScript(),
54
                'sigma' => $this->getSigma(),
55
            ],
56
            fn(mixed $val): bool => $val || is_numeric($val)
57
        );
58
    }
59
}
60