Issues (20)

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/Internal/ReflectionMethodFactory.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
namespace DependencyInjection\Internal;
4
5
class ReflectionMethodFactory implements ReflectionFactoryInterface
6
{
7
    /**
8
     * @var \ReflectionMethod
9
     */
10
    private $reflectionMethod;
11
12
    public function __construct($class, $name)
13
    {
14
        if (!is_string($class) && !is_object($class)) {
15
            throw Exception\ReflectionExceptionFactory::invalidArgument(
16
                sprintf("Parameter 1 of %s must be either class name or object.", __METHOD__)
17
            );
18
        }
19
20
        if (!isset($name) || !is_string($name)) {
21
            throw Exception\ReflectionExceptionFactory::invalidArgument(
22
                sprintf("Parameter 2 of %s must be either valid method name.", __METHOD__)
23
            );
24
        }
25
26
        $reflector = (is_string($class) ? ReflectionClassFactory::create($class)
27
            : ReflectionObjectFactory::create($class));
28
29
        if (!$reflector->hasMethod($name)) {
0 ignored issues
show
The method hasMethod does only exist in DependencyInjection\Inte...\ReflectionClassFactory, but not in DependencyInjection\Inte...ReflectionObjectFactory.

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...
30
            throw Exception\ReflectionExceptionFactory::reflectionInternal(
31
                sprintf("Class %s doesn't have method %s", __CLASS__, $name)
32
            );
33
        }
34
35
        $this->reflectionMethod = new \ReflectionMethod($class, $name);
36
    }
37
38
    public static function create($class, $name)
39
    {
40
        return new static($class, $name);
41
    }
42
43
    public static function export($class, $name, $return = false)
44
    {
45
        return \ReflectionMethod::export($class, $name, $return);
46
    }
47
48
    public function getClosure($object)
49
    {
50
        $closure = $this->reflectionMethod->getClosure($object);
51
52
        return ($closure instanceof \Closure ? $closure : null);
53
    }
54
55
    public function getDeclaringClass()
56
    {
57
        $declaringClass = $this->reflectionMethod->getDeclaringClass();
58
59
        return ($declaringClass instanceof \ReflectionClass ? $declaringClass : null);
60
    }
61
62
    public function getModifiers()
63
    {
64
        return $this->reflectionMethod->getModifiers();
65
    }
66
67
    public function getPrototype()
68
    {
69
        $prototype = $this->reflectionMethod->getPrototype();
70
71
        return ($prototype instanceof \ReflectionMethod ? $prototype : null);
72
    }
73
74
    public function invoke($object)
75
    {
76
        if (!is_object($object)) {
77
            throw Exception\ReflectionExceptionFactory::invalidArgument(
78
                sprintf("Parameter 1 of %s must be an object.", __METHOD__)
79
            );
80
        }
81
82
        return call_user_func_array([$this->reflectionMethod, 'invoke'],
83
            array_merge([$object], array_slice(func_get_args(), 1)));
84
    }
85
86
    public function invokeArgs($object, $args = [])
87
    {
88
        if (!is_object($object)) {
89
            throw Exception\ReflectionExceptionFactory::invalidArgument(
90
                sprintf("Parameter 1 of %s must be an object.", __METHOD__)
91
            );
92
        }
93
94
        if (!is_array($args)) {
95
            throw Exception\ReflectionExceptionFactory::invalidArgument(
96
                sprintf("Parameter 2 of %s must be an array.", __METHOD__)
97
            );
98
        }
99
100
        return $this->reflectionMethod->invokeArgs($object, $args);
101
    }
102
103
    public function isAbstract()
104
    {
105
        return $this->reflectionMethod->isAbstract();
106
    }
107
108
    public function isConstructor()
109
    {
110
        return $this->reflectionMethod->isConstructor();
111
    }
112
113
    public function isDestructor()
114
    {
115
        return $this->reflectionMethod->isDestructor();
116
    }
117
118
    public function isFinal()
119
    {
120
        return $this->reflectionMethod->isFinal();
121
    }
122
123
    public function isPrivate()
124
    {
125
        return $this->reflectionMethod->isPrivate();
126
    }
127
128
    public function isProtected()
129
    {
130
        return $this->reflectionMethod->isProtected();
131
    }
132
133
    public function isPublic()
134
    {
135
        return $this->reflectionMethod->isPublic();
136
    }
137
138
    public function isStatic()
139
    {
140
        return $this->reflectionMethod->isStatic();
141
    }
142
143
    public function setAccessible($accessible)
144
    {
145
        if (!is_bool($accessible)) {
146
            throw Exception\ReflectionExceptionFactory::invalidArgument(
147
                sprintf("Parameter 1 of %s must be a boolean.", __METHOD__)
148
            );
149
        }
150
151
        $this->reflectionMethod->setAccessible($accessible);
152
    }
153
154
    public function __toString()
155
    {
156
        return (string)$this->reflectionMethod;
157
    }
158
159
    public function getReflector()
160
    {
161
        return $this->reflectionMethod;
162
    }
163
}
164