These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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
|
|||
49 | $this->setMode($mode); |
||
50 | $this->missing = $missing; |
||
0 ignored issues
–
show
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 ![]() |
|||
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 |
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.