Completed
Pull Request — master (#348)
by
unknown
10:14
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
    }
38
39
    public function getMode(): string
40
    {
41
        return $this->mode;
42
    }
43
44
    public function setMode(?string $mode): static
45
    {
46
        $this->mode = $mode;
47
48
        return $this;
49
    }
50
51
    public function getMissing(): ?array
52
    {
53
        return $this->missing;
54
    }
55
56
    public function setMissing(?array $missing): static
57
    {
58
        $this->missing = $missing;
59
60
        return $this;
61
    }
62
63
    public function getType(): string
64
    {
65
        return 'matrix_stats';
66
    }
67
68
    protected function getArray(): array
69
    {
70
        $out = [];
71
        if ($this->getField()) {
72
            $out['fields'] = $this->getField();
73
        }
74
75
        if ($this->getMode()) {
76
            $out['mode'] = $this->getMode();
77
        }
78
79
80
        if ($this->getMissing()) {
81
            $out['missing'] = $this->getMissing();
82
        }
83
84
        return $out;
85
    }
86
}
87