MaxAggregation::getMissing()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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\Matrix;
13
14
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
15
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait;
16
17
/**
18
 * Class representing Max Aggregation.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html
21
 */
22
class MaxAggregation extends AbstractAggregation
23
{
24
    use MetricTrait;
25
26
    /**
27
     * @var string Used for multi value aggregation fields to pick a value.
28
     */
29
    private $mode;
30
31
    /**
32
     * @var array Defines how documents that are missing a value should be treated.
33
     */
34
    private $missing;
35
36
    /**
37
     * Inner aggregations container init.
38
     *
39
     * @param string $name
40
     * @param string|array $field Fields list to aggregate.
41
     * @param array $missing
42
     * @param string $mode
43
     */
44
    public function __construct($name, $field, $missing = null, $mode = null)
45
    {
46
        parent::__construct($name);
47
48
        $this->setField($field);
0 ignored issues
show
Bug introduced by
It seems like $field defined by parameter $field on line 44 can also be of type array; however, ONGR\ElasticsearchDSL\Ag...Aggregation::setField() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
49
        $this->setMode($mode);
50
        $this->missing = $missing;
0 ignored issues
show
Documentation Bug introduced by
It seems like $missing can be null. However, the property $missing is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getMode()
57
    {
58
        return $this->mode;
59
    }
60
61
    /**
62
     * @param string $mode
63
     *
64
     * @return $this
65
     */
66
    public function setMode($mode)
67
    {
68
        $this->mode = $mode;
69
70
        return $this;
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    public function getMissing()
77
    {
78
        return $this->missing;
79
    }
80
81
    /**
82
     * @param array $missing
83
     *
84
     * @return $this
85
     */
86
    public function setMissing($missing)
87
    {
88
        $this->missing = $missing;
89
90
        return $this;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function getType()
97
    {
98
        return 'matrix_stats';
99
    }
100
101
    protected function getArray()
102
    {
103
        $out = [];
104
        if ($this->getField()) {
105
            $out['fields'] = $this->getField();
106
        }
107
108
        if ($this->getMode()) {
109
            $out['mode'] = $this->getMode();
110
        }
111
112
113
        if ($this->getMissing()) {
114
            $out['missing'] = $this->getMissing();
115
        }
116
117
        return $out;
118
    }
119
}
120