Completed
Pull Request — master (#348)
by
unknown
01:15
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
/*
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\Metric;
13
14
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
15
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait;
16
use ONGR\ElasticsearchDSL\ScriptAwareTrait;
17
18
/**
19
 * Class representing Extended stats aggregation.
20
 *
21
 * @link http://goo.gl/E0PpDv
22
 */
23
class ExtendedStatsAggregation extends AbstractAggregation
24
{
25
    use MetricTrait;
26
27
    use ScriptAwareTrait;
28
29
    public function __construct(
30
        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...
31
        private ?string $field = null,
32
        private ?int $sigma = null,
33
        private ?string $script = null
34
    ) {
35
        parent::__construct($name);
36
37
        $this->setField($field);
38
        $this->setSigma($sigma);
39
        $this->setScript($script);
40
    }
41
42
    public function getSigma(): ?int
43
    {
44
        return $this->sigma;
45
    }
46
47
    public function setSigma(?int $sigma): static
48
    {
49
        $this->sigma = $sigma;
50
51
        return $this;
52
    }
53
54
    public function getType(): string
55
    {
56
        return 'extended_stats';
57
    }
58
59
    public function getArray(): array
60
    {
61
        return array_filter(
62
            [
63
                'field' => $this->getField(),
64
                'script' => $this->getScript(),
65
                'sigma' => $this->getSigma(),
66
            ],
67
            fn(mixed $val): bool => $val || is_numeric($val)
68
        );
69
    }
70
}
71