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

MaxAggregation   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 98
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
declare(strict_types=1);
13
14
namespace ONGR\ElasticsearchDSL\Aggregation\Matrix;
15
16
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
17
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait;
18
19
/**
20
 * Class representing Max Aggregation.
21
 *
22
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html
23
 */
24
class MatrixStatsAggregation extends AbstractAggregation
25
{
26
    use MetricTrait;
27
28
    public function __construct(
29
        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...
30
        private string|array $field,
31
        private ?array $missing = null,
32
        private ?string $mode = null
33
    ) {
34
        parent::__construct($name);
35
36
        $this->setField($field);
37
        $this->setMode($mode);
38
    }
39
40
    public function getMode(): string
41
    {
42
        return $this->mode;
43
    }
44
45
    public function setMode(?string $mode): static
46
    {
47
        $this->mode = $mode;
48
49
        return $this;
50
    }
51
52
    public function getMissing(): ?array
53
    {
54
        return $this->missing;
55
    }
56
57
    public function setMissing(?array $missing): static
58
    {
59
        $this->missing = $missing;
60
61
        return $this;
62
    }
63
64
    public function getType(): string
65
    {
66
        return 'matrix_stats';
67
    }
68
69
    protected function getArray(): array
70
    {
71
        $out = [];
72
        if ($this->getField()) {
73
            $out['fields'] = $this->getField();
74
        }
75
76
        if ($this->getMode()) {
77
            $out['mode'] = $this->getMode();
78
        }
79
80
81
        if ($this->getMissing()) {
82
            $out['missing'] = $this->getMissing();
83
        }
84
85
        return $out;
86
    }
87
}
88