Completed
Pull Request — master (#348)
by
unknown
01:15
created

StatsAggregation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 44
c 0
b 0
f 0
rs 10
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
declare(strict_types=1);
13
14
namespace ONGR\ElasticsearchDSL\Aggregation\Metric;
15
16
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
17
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait;
18
use ONGR\ElasticsearchDSL\ScriptAwareTrait;
19
20
/**
21
 * Class representing StatsAggregation.
22
 *
23
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html
24
 */
25
class StatsAggregation extends AbstractAggregation
26
{
27
    use MetricTrait;
28
29
    use ScriptAwareTrait;
30
31
    public function __construct(
32
        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...
33
        private ?string $field = null,
34
        ?string $script = null
35
    ) {
36
        parent::__construct($name);
37
38
        $this->setField($field);
39
        $this->setScript($script);
40
    }
41
42
    public function getType(): string
43
    {
44
        return 'stats';
45
    }
46
47
    public function getArray(): array
48
    {
49
        $out = [];
50
51
        if ($this->getField()) {
52
            $out['field'] = $this->getField();
53
        }
54
55
        if ($this->getScript()) {
56
            $out['script'] = $this->getScript();
57
        }
58
59
        return $out;
60
    }
61
}
62