Issues (46)

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/Parser/PHPDocClass.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
3
namespace Atrapalo\PHPTools\Parser;
4
5
use Atrapalo\PHPTools\Parser\Values\Method;
6
use Atrapalo\PHPTools\Parser\Values\Param;
7
8
/**
9
 * Class PHPDocClass
10
 * @package Atrapalo\PHPTools\Parser
11
 *
12
 * @author Guillermo González <[email protected]>
13
 */
14
class PHPDocClass
15
{
16
    /**
17
     * @param string $className
18
     * @return Method[]
19
     */
20 4
    public static function staticMethods(string $className): array
21
    {
22 4
        $classDoc = self::docComment($className);
23
24 3
        preg_match_all(
25 3
            '/^[* ]+@method(?>\hstatic) ?([a-zA-Z0-9_\-\$\\\ ]*) (\w+)\(([a-zA-Z0-9_\-$,\\\ ]*)\) ?(.*)$/im',
26 3
            $classDoc,
27 3
            $staticMethodsOfDoc,
28 3
            PREG_SET_ORDER
29
        );
30
31 3
        return self::createMethods($staticMethodsOfDoc, true);
0 ignored issues
show
It seems like $staticMethodsOfDoc can also be of type null; however, Atrapalo\PHPTools\Parser...cClass::createMethods() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
32
    }
33
34
    /**
35
     * @param string $className
36
     * @return Method[]
37
     */
38 4
    public static function methods(string $className): array
39
    {
40 4
        $classDoc = self::docComment($className);
41
42 3
        preg_match_all(
43 3
            '/^[* ]+@method(?!.*static )([a-zA-Z0-9_\-\$\\\ ]*) (\w+)\(([a-zA-Z0-9_\-$,\\\ ]*)\) ?(.*)$/mi',
44 3
            $classDoc,
45 3
            $staticMethodsOfDoc,
46 3
            PREG_SET_ORDER
47
        );
48
49 3
        return self::createMethods($staticMethodsOfDoc, false);
0 ignored issues
show
It seems like $staticMethodsOfDoc can also be of type null; however, Atrapalo\PHPTools\Parser...cClass::createMethods() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
50
    }
51
52
    /**
53
     * @param string $className
54
     * @return string
55
     */
56 8
    private static function docComment(string $className): string
57
    {
58 8
        $rc = new \ReflectionClass($className);
59
60 6
        return $rc->getDocComment();
61
    }
62
63
    /**
64
     * @param array $methodsOfDoc
65
     * @param bool  $areStatics
66
     * @return array
67
     */
68 6
    private static function createMethods(array $methodsOfDoc, bool $areStatics): array
69
    {
70 6
        $methods = [];
71 6
        foreach ($methodsOfDoc as $methodOfDoc) {
72 4
            $return = isset($methodOfDoc[1]) ? trim($methodOfDoc[1]) : '';
73 4
            $name = isset($methodOfDoc[2]) ? trim($methodOfDoc[2]) : '';
74 4
            $params = isset($methodOfDoc[3]) ? self::parseParams($methodOfDoc[3]) : [];
75 4
            $description = isset($methodOfDoc[4]) ? trim($methodOfDoc[4]) : '';
76
77 4
            $method = new Method($areStatics, $name);
78 4
            $method->setReturn($return)
79 4
                ->setDescription($description)
80 4
                ->setParams($params);
81
82 4
            $methods[] = $method;
83
        }
84
85 6
        return $methods;
86
    }
87
88
    /**
89
     * @param string $stringParams
90
     * @return array
91
     */
92 4
    private static function parseParams(string $stringParams): array
93
    {
94 4
        $params = [];
95 4
        if (!empty($stringParams)){
96 2
            $paramsSlice = explode(',', $stringParams);
97 2
            foreach ($paramsSlice as $paramElement) {
98 2
                preg_match('/([\\a-z]*)\h?(\$\w+)/i', $paramElement, $paramData);
99 2
                if (count($paramData) == 3) {
100 2
                    $type = isset($paramData[1]) ? trim($paramData[1]) : '';
101 2
                    $name = isset($paramData[2]) ? trim($paramData[2]) : '';
102
103 2
                    $params[] = new Param($name, $type);
104
                }
105
            }
106
        }
107
108 4
        return $params;
109
    }
110
}
111