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/AbstractAggregation.php (1 issue)

Labels
Severity

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;
13
14
use ONGR\ElasticsearchDSL\BuilderBag;
15
use ONGR\ElasticsearchDSL\NameAwareTrait;
16
use ONGR\ElasticsearchDSL\NamedBuilderInterface;
17
use ONGR\ElasticsearchDSL\ParametersTrait;
18
19
/**
20
 * AbstractAggregation class.
21
 */
22
abstract class AbstractAggregation implements NamedBuilderInterface
23
{
24
    use ParametersTrait;
25
    use NameAwareTrait;
26
27
    /**
28
     * @var string
29
     */
30
    private $field;
31
32
    /**
33
     * @var BuilderBag
34
     */
35
    private $aggregations;
36
37
    /**
38
     * Abstract supportsNesting method.
39
     *
40
     * @return bool
41
     */
42
    abstract protected function supportsNesting();
43
44
    /**
45
     * @return array|\stdClass
46
     */
47
    abstract protected function getArray();
48
49
    /**
50
     * Inner aggregations container init.
51
     *
52
     * @param string $name
53
     */
54
    public function __construct($name)
55
    {
56
        $this->setName($name);
57
    }
58
59
    /**
60
     * @param string $field
61
     *
62
     * @return $this
63
     */
64
    public function setField($field)
65
    {
66
        $this->field = $field;
67
68
        return $this;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getField()
75
    {
76
        return $this->field;
77
    }
78
79
    /**
80
     * Adds a sub-aggregation.
81
     *
82
     * @param AbstractAggregation $abstractAggregation
83
     *
84
     * @return $this
85
     */
86
    public function addAggregation(AbstractAggregation $abstractAggregation)
87
    {
88
        if (!$this->aggregations) {
89
            $this->aggregations = $this->createBuilderBag();
90
        }
91
92
        $this->aggregations->add($abstractAggregation);
93
        
94
        return $this;
95
    }
96
97
    /**
98
     * Returns all sub aggregations.
99
     *
100
     * @return BuilderBag[]|NamedBuilderInterface[]
101
     */
102
    public function getAggregations()
103
    {
104
        if ($this->aggregations) {
105
            return $this->aggregations->all();
106
        } else {
107
            return [];
108
        }
109
    }
110
111
    /**
112
     * Returns sub aggregation.
113
     * @param string $name Aggregation name to return.
114
     *
115
     * @return AbstractAggregation|NamedBuilderInterface|null
116
     */
117
    public function getAggregation($name)
118
    {
119
        if ($this->aggregations && $this->aggregations->has($name)) {
120
            return $this->aggregations->get($name);
121
        } else {
122
            return null;
123
        }
124
    }
125
126
    /**
127
     * {@inheritdoc}
128
     */
129
    public function toArray()
130
    {
131
        $array = $this->getArray();
132
        $result = [
133
            $this->getType() => is_array($array) ? $this->processArray($array) : $array,
134
        ];
135
136
        if ($this->supportsNesting()) {
137
            $nestedResult = $this->collectNestedAggregations();
138
139
            if (!empty($nestedResult)) {
140
                $result['aggregations'] = $nestedResult;
141
            }
142
        }
143
144
        return $result;
145
    }
146
147
    /**
148
     * Process all nested aggregations.
149
     *
150
     * @return array
151
     */
152
    protected function collectNestedAggregations()
153
    {
154
        $result = [];
155
        /** @var AbstractAggregation $aggregation */
156
        foreach ($this->getAggregations() as $aggregation) {
157
            $result[$aggregation->getName()] = $aggregation->toArray();
0 ignored issues
show
The method getName does only exist in ONGR\ElasticsearchDSL\NamedBuilderInterface, but not in ONGR\ElasticsearchDSL\BuilderBag.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
158
        }
159
160
        return $result;
161
    }
162
163
    /**
164
     * Creates BuilderBag new instance.
165
     *
166
     * @return BuilderBag
167
     */
168
    private function createBuilderBag()
169
    {
170
        return new BuilderBag();
171
    }
172
}
173