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/Metric/TopHitsAggregation.php (3 issues)

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\Metric;
13
14
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
15
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait;
16
use ONGR\ElasticsearchDSL\BuilderInterface;
17
18
/**
19
 * Top hits aggregation.
20
 *
21
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html
22
 */
23
class TopHitsAggregation extends AbstractAggregation
24
{
25
    use MetricTrait;
26
27
    /**
28
     * @var int Number of top matching hits to return per bucket.
29
     */
30
    private $size;
31
32
    /**
33
     * @var int The offset from the first result you want to fetch.
34
     */
35
    private $from;
36
37
    /**
38
     * @var BuilderInterface[] How the top matching hits should be sorted.
39
     */
40
    private $sorts = [];
41
42
    /**
43
     * Constructor for top hits.
44
     *
45
     * @param string                $name Aggregation name.
46
     * @param null|int              $size Number of top matching hits to return per bucket.
47
     * @param null|int              $from The offset from the first result you want to fetch.
48
     * @param null|BuilderInterface $sort How the top matching hits should be sorted.
49
     */
50
    public function __construct($name, $size = null, $from = null, $sort = null)
51
    {
52
        parent::__construct($name);
53
        $this->setFrom($from);
54
        $this->setSize($size);
55
        $this->addSort($sort);
0 ignored issues
show
It seems like $sort defined by parameter $sort on line 50 can be null; however, ONGR\ElasticsearchDSL\Ag...sAggregation::addSort() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
56
    }
57
58
    /**
59
     * Return from.
60
     *
61
     * @return int
62
     */
63
    public function getFrom()
64
    {
65
        return $this->from;
66
    }
67
68
    /**
69
     * @param int $from
70
     *
71
     * @return $this
72
     */
73
    public function setFrom($from)
74
    {
75
        $this->from = $from;
76
77
        return $this;
78
    }
79
80
    /**
81
     * @return BuilderInterface[]
82
     */
83
    public function getSorts()
84
    {
85
        return $this->sorts;
86
    }
87
88
    /**
89
     * @param BuilderInterface[] $sorts
90
     *
91
     * @return $this
92
     */
93
    public function setSorts(array $sorts)
94
    {
95
        $this->sorts = $sorts;
96
97
        return $this;
98
    }
99
100
    /**
101
     * Add sort.
102
     *
103
     * @param BuilderInterface $sort
104
     */
105
    public function addSort($sort)
106
    {
107
        $this->sorts[] = $sort;
108
    }
109
110
    /**
111
     * @param int $size
112
     *
113
     * @return $this
114
     */
115
    public function setSize($size)
116
    {
117
        $this->size = $size;
118
119
        return $this;
120
    }
121
122
    /**
123
     * Return size.
124
     *
125
     * @return int
126
     */
127
    public function getSize()
128
    {
129
        return $this->size;
130
    }
131
132
    /**
133
     * {@inheritdoc}
134
     */
135
    public function getType()
136
    {
137
        return 'top_hits';
138
    }
139
140
    /**
141
     * {@inheritdoc}
142
     */
143
    public function getArray()
144
    {
145
        $sortsOutput = [];
146
        $addedSorts = array_filter($this->getSorts());
147
        if ($addedSorts) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $addedSorts of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
148
            foreach ($addedSorts as $sort) {
149
                $sortsOutput[] = $sort->toArray();
150
            }
151
        } else {
152
            $sortsOutput = null;
153
        }
154
155
        $output = array_filter(
156
            [
157
                'sort' => $sortsOutput,
158
                'size' => $this->getSize(),
159
                'from' => $this->getFrom(),
160
            ],
161
            function ($val) {
162
                return (($val || is_array($val) || ($val || is_numeric($val))));
163
            }
164
        );
165
166
        return empty($output) ? new \stdClass() : $output;
167
    }
168
169
    /**
170
     * @deprecated sorts now is a container, use `getSorts()`instead.
171
     * Return sort.
172
     *
173
     * @return BuilderInterface
174
     */
175
    public function getSort()
176
    {
177
        if (isset($this->sorts[0])) {
178
            return $this->sorts[0];
179
        }
180
181
        return null;
182
    }
183
184
    /**
185
     * @deprecated sorts now is a container, use `addSort()`instead.
186
     *
187
     * @param BuilderInterface $sort
188
     *
189
     * @return $this
190
     */
191
    public function setSort(BuilderInterface $sort)
192
    {
193
        $this->sort = $sort;
0 ignored issues
show
The property sort does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
194
195
        return $this;
196
    }
197
}
198