Issues (4)

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/Validator.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
namespace Dgame\Object;
4
5
use Dgame\Type\TypeFactory;
6
use ReflectionMethod;
7
use ReflectionParameter;
8
use Throwable;
9
10
/**
11
 * Class Validator
12
 * @package Dgame\Object
13
 */
14
final class Validator
15
{
16
    /**
17
     * @var ObjectFacade
18
     */
19
    private $facade;
20
21
    /**
22
     * Validator constructor.
23
     *
24
     * @param ObjectFacade $facade
25
     */
26 4
    public function __construct(ObjectFacade $facade)
27
    {
28 4
        $this->facade = $facade;
29 4
    }
30
31
    /**
32
     * @param ObjectFacade $facade
33
     *
34
     * @return Validator
0 ignored issues
show
Should the return type not be \self?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
35
     */
36 4
    public static function new(ObjectFacade $facade): self
37
    {
38 4
        return new self($facade);
39
    }
40
41
    /**
42
     * @param ReflectionMethod $method
43
     * @param mixed            $value
44
     *
45
     * @return bool
46 3
     */
47
    public function isValidSetterMethod(ReflectionMethod $method, $value): bool
48 3
    {
49
        if (!$method->isPublic()) {
50
            return false;
51
        }
52
53
        if ($method->getNumberOfParameters() === 0) {
54
            return true;
55
        }
56 2
57
        if ($method->getNumberOfRequiredParameters() > 1) {
58 2
            return false;
59
        }
60
61
        if ($value === null) {
62
            return $method->getParameters()[0]->allowsNull();
63
        }
64
65
        return $this->isValidParameterValue($method->getParameters()[0], $value);
66
    }
67 1
68
    /**
69 1
     * @param ReflectionParameter $parameter
70
     * @param mixed               $value
71
     *
72
     * @return bool
73 1
     */
74 1
    public function isValidParameterValue(ReflectionParameter $parameter, $value): bool
75
    {
76
        return !$parameter->hasType() || TypeFactory::reflection($parameter)->accept($value);
77 1
    }
78
79
    /**
80
     * @param ReflectionMethod $method
81 1
     *
82 1
     * @return bool
83
     */
84
    public function isValidGetterMethod(ReflectionMethod $method): bool
85 1
    {
86
        if (!$method->isPublic()) {
87
            return false;
88
        }
89
90
        try {
91
            $value = $method->invoke($this->facade->getObject());
92
        } catch (Throwable $t) {
93
            return false;
94 1
        }
95
96 1
        $returnType = $method->getReturnType();
97
98
        return $value !== null || $returnType === null || $returnType->allowsNull();
99
    }
100
101
    /**
102
     * @param ReflectionMethod $method
103
     * @param array            ...$args
104 2
     *
105
     * @return bool
106 2
     */
0 ignored issues
show
Consider making the type for parameter $args a bit more specific; maybe use array[].
Loading history...
107
    public function areValidMethodArguments(ReflectionMethod $method, ...$args): bool
108
    {
109
        if (!$method->isPublic()) {
110 2
            return false;
111
        }
112 2
113
        if (count($args) < $method->getNumberOfRequiredParameters()) {
114
            return false;
115
        }
116
117
        return $this->validateMethodArguments($method, ...$args);
118
    }
119
120
    /**
121
     * @param ReflectionMethod $method
122
     * @param array            ...$args
123
     *
124
     * @return bool
125
     */
0 ignored issues
show
Consider making the type for parameter $args a bit more specific; maybe use array[].
Loading history...
126
    private function validateMethodArguments(ReflectionMethod $method, ...$args): bool
127
    {
128
        $parameters = $method->getParameters();
129
        foreach ($args as $i => $arg) {
130
            if (!array_key_exists($i, $parameters)) {
131
                break;
132
            }
133
134
            if ($arg === null && !$parameters[$i]->allowsNull()) {
135
                return false;
136
            }
137
138
            if (!$this->isValidParameterValue($parameters[$i], $arg)) {
139
                return false;
140
            }
141
        }
142
143
        return true;
144
    }
145
}
146
147