Completed
Push — master ( e193aa...801803 )
by Simonas
08:06
created

MaxAggregation::setMode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
14
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait;
15
16
/**
17
 * Class representing Max Aggregation.
18
 *
19
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html
20
 */
21
class MaxAggregation extends AbstractAggregation
22
{
23
    use MetricTrait;
24
25
    /**
26
     * @var string Used for multi value aggregation fields to pick a value.
27
     */
28
    private $mode;
29
30
    /**
31
     * @var array Defines how documents that are missing a value should be treated.
32
     */
33
    private $missing;
34
35
    /**
36
     * Inner aggregations container init.
37
     *
38
     * @param string $name
39
     * @param string|array $field Fields list to aggregate.
40
     * @param array $missing
41
     * @param string $mode
42
     */
43
    public function __construct($name, $field, $missing = null, $mode = null)
44
    {
45
        parent::__construct($name);
46
47
        $this->setField($field);
0 ignored issues
show
Bug introduced by
It seems like $field defined by parameter $field on line 43 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...
48
        $this->setMode($mode);
49
        $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...
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getMode()
56
    {
57
        return $this->mode;
58
    }
59
60
    /**
61
     * @param string $mode
62
     */
63
    public function setMode($mode)
64
    {
65
        $this->mode = $mode;
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    public function getMissing()
72
    {
73
        return $this->missing;
74
    }
75
76
    /**
77
     * @param array $missing
78
     */
79
    public function setMissing($missing)
80
    {
81
        $this->missing = $missing;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function getType()
88
    {
89
        return 'matrix_stats';
90
    }
91
92
    protected function getArray()
93
    {
94
        $out = [];
95
        if ($this->getField()) {
96
            $out['fields'] = $this->getField();
97
        }
98
99
        if($this->getMode()) {
100
            $out['mode'] = $this->getMode();
101
        }
102
103
104
        if($this->getMissing()) {
105
            $out['missing'] = $this->getMissing();
106
        }
107
108
        return $out;
109
    }
110
}
111