Issues (63)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Aggregation/Bucketing/HistogramAggregation.php (1 issue)

Upgrade to new PHP Analysis Engine

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\Bucketing;
13
14
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
15
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;
16
17
/**
18
 * Class representing Histogram aggregation.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html
21
 */
22
class HistogramAggregation extends AbstractAggregation
23
{
24
    use BucketingTrait;
25
26
    const DIRECTION_ASC = 'asc';
27
    const DIRECTION_DESC = 'desc';
28
29
    /**
30
     * @var int
31
     */
32
    protected $interval;
33
34
    /**
35
     * @var int
36
     */
37
    protected $minDocCount;
38
39
    /**
40
     * @var array
41
     */
42
    protected $extendedBounds;
43
44
    /**
45
     * @var string
46
     */
47
    protected $orderMode;
48
49
    /**
50
     * @var string
51
     */
52
    protected $orderDirection;
53
54
    /**
55
     * @var bool
56
     */
57
    protected $keyed;
58
59
    /**
60
     * Inner aggregations container init.
61
     *
62
     * @param string $name
63
     * @param string $field
64
     * @param int    $interval
65
     * @param int    $minDocCount
66
     * @param string $orderMode
67
     * @param string $orderDirection
68
     * @param int    $extendedBoundsMin
69
     * @param int    $extendedBoundsMax
70
     * @param bool   $keyed
71
     */
72
    public function __construct(
73
        $name,
74
        $field = null,
75
        $interval = null,
76
        $minDocCount = null,
77
        $orderMode = null,
78
        $orderDirection = self::DIRECTION_ASC,
79
        $extendedBoundsMin = null,
80
        $extendedBoundsMax = null,
81
        $keyed = null
82
    ) {
83
        parent::__construct($name);
84
85
        $this->setField($field);
86
        $this->setInterval($interval);
87
        $this->setMinDocCount($minDocCount);
88
        $this->setOrder($orderMode, $orderDirection);
89
        $this->setExtendedBounds($extendedBoundsMin, $extendedBoundsMax);
90
        $this->setKeyed($keyed);
0 ignored issues
show
It seems like $keyed defined by parameter $keyed on line 81 can also be of type null; however, ONGR\ElasticsearchDSL\Ag...Aggregation::setKeyed() does only seem to accept boolean, 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...
91
    }
92
93
    /**
94
     * @return bool
95
     */
96
    public function isKeyed()
97
    {
98
        return $this->keyed;
99
    }
100
101
    /**
102
     * Get response as a hash instead keyed by the buckets keys.
103
     *
104
     * @param bool $keyed
105
     *
106
     * @return $this
107
     */
108
    public function setKeyed($keyed)
109
    {
110
        $this->keyed = $keyed;
111
112
        return $this;
113
    }
114
115
    /**
116
     * Sets buckets ordering.
117
     *
118
     * @param string $mode
119
     * @param string $direction
120
     *
121
     * @return $this
122
     */
123
    public function setOrder($mode, $direction = self::DIRECTION_ASC)
124
    {
125
        $this->orderMode = $mode;
126
        $this->orderDirection = $direction;
127
128
        return $this;
129
    }
130
131
    /**
132
     * @return array
133
     */
134
    public function getOrder()
135
    {
136
        if ($this->orderMode && $this->orderDirection) {
137
            return [$this->orderMode => $this->orderDirection];
138
        } else {
139
            return null;
140
        }
141
    }
142
143
    /**
144
     * @return int
145
     */
146
    public function getInterval()
147
    {
148
        return $this->interval;
149
    }
150
151
    /**
152
     * @param int $interval
153
     *
154
     * @return $this
155
     */
156
    public function setInterval($interval)
157
    {
158
        $this->interval = $interval;
159
160
        return $this;
161
    }
162
163
    /**
164
     * @return int
165
     */
166
    public function getMinDocCount()
167
    {
168
        return $this->minDocCount;
169
    }
170
171
    /**
172
     * Set limit for document count buckets should have.
173
     *
174
     * @param int $minDocCount
175
     *
176
     * @return $this
177
     */
178
    public function setMinDocCount($minDocCount)
179
    {
180
        $this->minDocCount = $minDocCount;
181
182
        return $this;
183
    }
184
185
    /**
186
     * @return array
187
     */
188
    public function getExtendedBounds()
189
    {
190
        return $this->extendedBounds;
191
    }
192
193
    /**
194
     * @param int $min
195
     * @param int $max
196
     *
197
     * @return $this
198
     */
199
    public function setExtendedBounds($min = null, $max = null)
200
    {
201
        $bounds = array_filter(
202
            [
203
                'min' => $min,
204
                'max' => $max,
205
            ],
206
            'strlen'
207
        );
208
        $this->extendedBounds = $bounds;
209
210
        return $this;
211
    }
212
213
    /**
214
     * {@inheritdoc}
215
     */
216
    public function getType()
217
    {
218
        return 'histogram';
219
    }
220
221
    /**
222
     * {@inheritdoc}
223
     */
224
    public function getArray()
225
    {
226
        $out = array_filter(
227
            [
228
                'field' => $this->getField(),
229
                'interval' => $this->getInterval(),
230
                'min_doc_count' => $this->getMinDocCount(),
231
                'extended_bounds' => $this->getExtendedBounds(),
232
                'keyed' => $this->isKeyed(),
233
                'order' => $this->getOrder(),
234
            ],
235
            function ($val) {
236
                return ($val || is_numeric($val));
237
            }
238
        );
239
        $this->checkRequiredParameters($out, ['field', 'interval']);
240
241
        return $out;
242
    }
243
244
    /**
245
     * Checks if all required parameters are set.
246
     *
247
     * @param array $data
248
     * @param array $required
249
     *
250
     * @throws \LogicException
251
     */
252
    protected function checkRequiredParameters($data, $required)
253
    {
254
        if (count(array_intersect_key(array_flip($required), $data)) !== count($required)) {
255
            throw new \LogicException('Histogram aggregation must have field and interval set.');
256
        }
257
    }
258
}
259