Issues (138)

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.

SourceLocator/Type/Composer/Psr/Psr4Mapping.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
declare(strict_types=1);
4
5
namespace Roave\BetterReflection\SourceLocator\Type\Composer\Psr;
6
7
use Roave\BetterReflection\Identifier\Identifier;
8
use Roave\BetterReflection\SourceLocator\Type\Composer\Psr\Exception\InvalidPrefixMapping;
9
use function array_filter;
10
use function array_keys;
11
use function array_map;
12
use function array_merge;
13
use function array_unique;
14
use function array_values;
15
use function is_dir;
16
use function ltrim;
17
use function rtrim;
18
use function str_replace;
19
use function strlen;
20
use function strpos;
21
use function substr;
22
use const ARRAY_FILTER_USE_KEY;
23
24
final class Psr4Mapping implements PsrAutoloaderMapping
25
{
26
    /** @var array<string, array<int, string>> */
27
    private $mappings = [];
28
29 16
    private function __construct()
30
    {
31 16
    }
32
33
    /** @param array<string, array<int, string>> $mappings */
34 21 View Code Duplication
    public static function fromArrayMappings(array $mappings) : self
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36 21
        self::assertValidMapping($mappings);
37
38 16
        $instance = new self();
39
40 16
        $instance->mappings = array_map(
41
            static function (array $directories) : array {
42
                return array_map(static function (string $directory) : string {
43 15
                    return rtrim($directory, '/');
44 15
                }, $directories);
45 16
            },
46 16
            $mappings
47
        );
48
49 16
        return $instance;
50
    }
51
52
    /** {@inheritDoc} */
53 6
    public function resolvePossibleFilePaths(Identifier $identifier) : array
54
    {
55 6
        if (! $identifier->isClass()) {
56 1
            return [];
57
        }
58
59 5
        $className        = $identifier->getName();
60 5
        $matchingPrefixes = $this->matchingPrefixes($className);
61
62 5
        return array_values(array_filter(array_merge(
63 5
            [],
64
            ...array_map(static function (array $paths, string $prefix) use ($className) : array {
65 4
                $subPath = ltrim(str_replace('\\', '/', substr($className, strlen($prefix))), '/');
66
67 4
                if ($subPath === '') {
68 2
                    return [];
69
                }
70
71
                return array_map(static function (string $path) use ($subPath) : string {
72 3
                    return rtrim($path, '/') . '/' . $subPath . '.php';
73 3
                }, $paths);
74 5
            }, $matchingPrefixes, array_keys($matchingPrefixes))
75
        )));
76
    }
77
78
    /** @return array<string, array<int, string>> */
0 ignored issues
show
The doc-type array<string, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
79 5
    private function matchingPrefixes(string $className) : array
80
    {
81 5
        return array_filter(
82 5
            $this->mappings,
83
            static function (string $prefix) use ($className) : bool {
84 4
                return strpos($className, $prefix) === 0;
85 5
            },
86 5
            ARRAY_FILTER_USE_KEY
87
        );
88
    }
89
90
    /** {@inheritDoc} */
91 5
    public function directories() : array
92
    {
93 5
        return array_values(array_unique(array_merge([], ...array_values($this->mappings))));
94
    }
95
96
    /**
97
     * @param array<string, array<int, string>> $mappings
98
     *
99
     * @throws InvalidPrefixMapping
100
     */
101 21 View Code Duplication
    private static function assertValidMapping(array $mappings) : void
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
102
    {
103 21
        foreach ($mappings as $prefix => $paths) {
104 20
            if ($prefix === '') {
105 1
                throw InvalidPrefixMapping::emptyPrefixGiven();
106
            }
107
108 19
            if ($paths === []) {
109 1
                throw InvalidPrefixMapping::emptyPrefixMappingGiven($prefix);
110
            }
111
112 18
            foreach ($paths as $path) {
113 18
                if (! is_dir($path)) {
114 3
                    throw InvalidPrefixMapping::prefixMappingIsNotADirectory($prefix, $path);
115
                }
116
            }
117
        }
118 16
    }
119
}
120