Issues (7)

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/Generator/Template/ClassTemplate.php (2 issues)

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
declare(strict_types=1);
3
4
namespace Moka\Generator\Template;
5
6
use Moka\Exception\InvalidArgumentException;
7
use Moka\Proxy\ProxyInterface;
8
use Moka\Proxy\ProxyTrait;
9
10
/**
11
 * Class ClassTemplate
12
 * @package Moka\Generator\Template
13
 */
14
class ClassTemplate implements TemplateInterface
15
{
16
    private const UNSAFE_METHODS = ['__construct', '__destruct', '__call', '__get', '__clone'];
17
18
    private const TEMPLATE_FQCN = 'Moka_%s_%s';
19
20
    private const TEMPLATE_CLASS = '
21
    class %s extends %s implements %s
22
    {
23
        use %s;
24
        
25
        %s
26
27
        public function __construct()
28
        {
29
            %s
30
        }
31
        
32
        public function __call(%s $name, %s $arguments)
33
        {
34
            return $this->doCall($name, $arguments);
35
        }
36
        
37
        public function __get(%s $name)
38
        {
39
            return $this->doGet($name);
40
        }
41
42
        %s
43
    };
44
    
45
    return "%s";
46
    ';
47
48
    /**
49
     * @param \Reflector|\ReflectionClass $class
50
     * @return string
51
     */
52 11
    public static function generate(\Reflector $class): string
53
    {
54 11
        return static::doGenerate($class);
55
    }
56
57
    /**
58
     * @param \ReflectionClass $class
59
     * @return string
60
     * @throws \RuntimeException
61
     * @throws InvalidArgumentException
62
     */
63 11
    protected static function doGenerate(\ReflectionClass $class): string
64
    {
65 11
        $properties = $class->getProperties(\ReflectionProperty::IS_PUBLIC);
66 11
        $propertiesCode = [];
67
68 11
        $constructorCode = [];
69
70 11
        $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
71 11
        $methodsCode = [];
72
73 11
        $callParametersTypes = array_fill(0, 2, '');
74 11
        $getNameType = '';
75
76 11
        foreach ($properties as $property) {
77 5
            if ($property->isStatic()) {
78 5
                continue;
79
            }
80
81 5
            $propertiesCode[] = PropertyTemplate::generate($property);
82 5
            $constructorCode[] = PropertyInitializationTemplate::generate($property);
83
        }
84
85 11
        foreach ($methods as $method) {
86
            if (
87 10
                !$method->isFinal() &&
88 10
                !\in_array($method->name, self::UNSAFE_METHODS, $strict = true)
89
            ) {
90 10
                $methodsCode[] = MethodTemplate::generate($method);
91
            }
92
93 10
            if ('__call' === $method->name) {
94 2
                $callParameters = $method->getParameters();
95 2
                foreach ($callParameters as $callParameter) {
96 2
                    $callParametersTypes[$callParameter->getPosition()] = $callParameter->getType()
97 1
                        ? $callParameter->getType()->getName()
98 2
                        : null;
99
                }
100
            }
101
102 10
            if ('__get' === $method->name) {
103
                $geFirstParameter = $method->getParameters()[0];
104
                $getNameType = $geFirstParameter->getType()
105
                    ? $geFirstParameter->getType()->getName()
106
                    : null;
107
            }
108
        }
109
110 11
        $mockClassName = $class->name;
111 11
        $proxyClassName = sprintf(
112 11
            self::TEMPLATE_FQCN,
113 11
            preg_replace('/\\\/', '__', $mockClassName),
114 11
            random_int($min = 0, $max = PHP_INT_MAX)
115
        );
116
117 11
        [$callNameType, $callArgumentsType] = $callParametersTypes;
0 ignored issues
show
The variable $callNameType does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The variable $callArgumentsType does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
118
119 11
        return sprintf(
120 11
            self::TEMPLATE_CLASS,
121
            $proxyClassName,
122
            $mockClassName,
123 11
            ProxyInterface::class,
124 11
            ProxyTrait::class,
125 11
            implode(PHP_EOL, $propertiesCode),
126 11
            implode(PHP_EOL, $constructorCode),
127 11
            $callNameType ?: '',
128 11
            $callArgumentsType ?: '',
129 11
            $getNameType ?: '',
130 11
            implode(PHP_EOL, $methodsCode),
131
            $proxyClassName
132
        );
133
    }
134
}
135