Issues (135)

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.

Composer/Factory/MakeLocatorForInstalledJson.php (7 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\Factory;
6
7
use Roave\BetterReflection\SourceLocator\Ast\Locator;
8
use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
9
use Roave\BetterReflection\SourceLocator\Type\Composer\Factory\Exception\FailedToParseJson;
10
use Roave\BetterReflection\SourceLocator\Type\Composer\Factory\Exception\InvalidProjectDirectory;
11
use Roave\BetterReflection\SourceLocator\Type\Composer\Factory\Exception\MissingInstalledJson;
12
use Roave\BetterReflection\SourceLocator\Type\Composer\Psr\Psr0Mapping;
13
use Roave\BetterReflection\SourceLocator\Type\Composer\Psr\Psr4Mapping;
14
use Roave\BetterReflection\SourceLocator\Type\Composer\PsrAutoloaderLocator;
15
use Roave\BetterReflection\SourceLocator\Type\DirectoriesSourceLocator;
16
use Roave\BetterReflection\SourceLocator\Type\SingleFileSourceLocator;
17
use Roave\BetterReflection\SourceLocator\Type\SourceLocator;
18
use function array_filter;
19
use function array_map;
20
use function array_merge;
21
use function array_merge_recursive;
22
use function file_exists;
23
use function file_get_contents;
24
use function is_array;
25
use function is_dir;
26
use function json_decode;
27
use function realpath;
28
29
final class MakeLocatorForInstalledJson
30
{
31 6
    public function __invoke(string $installationPath, Locator $astLocator) : SourceLocator
32
    {
33 6
        $realInstallationPath = (string) realpath($installationPath);
34
35 6
        if (! is_dir($realInstallationPath)) {
36 1
            throw InvalidProjectDirectory::atPath($installationPath);
37
        }
38
39 5
        $installedJsonPath = $realInstallationPath . '/vendor/composer/installed.json';
40
41 5
        if (! file_exists($installedJsonPath)) {
42 1
            throw MissingInstalledJson::inProjectPath($installationPath);
43
        }
44
45
        /** @var list<array{name: string, autoload: array{classmap: array<int, string>, files: array<int, string>, psr-4: array<string, array<int, string>>, psr-0: array<string, array<int, string>>}}>|null $installed */
46 4
        $installed = json_decode((string) file_get_contents($installedJsonPath), true);
47
48 4
        if (! is_array($installed)) {
49 1
            throw FailedToParseJson::inFile($installedJsonPath);
50
        }
51
52 3
        $classMapPaths       = array_merge(
53 3
            [],
54
            ...array_map(function (array $package) use ($realInstallationPath) : array {
55 3
                return $this->prefixPaths(
56 3
                    $this->packageToClassMapPaths($package),
57 3
                    $this->packagePrefixPath($realInstallationPath, $package)
58
                );
59 3
            }, $installed)
60
        );
61 3
        $classMapFiles       = array_filter($classMapPaths, 'is_file');
62 3
        $classMapDirectories = array_filter($classMapPaths, 'is_dir');
63 3
        $filePaths           = array_merge(
64 3
            [],
65
            ...array_map(function (array $package) use ($realInstallationPath) : array {
66 3
                return $this->prefixPaths(
67 3
                    $this->packageToFilePaths($package),
68 3
                    $this->packagePrefixPath($realInstallationPath, $package)
69
                );
70 3
            }, $installed)
71
        );
72
73 3
        return new AggregateSourceLocator(array_merge(
74
            [
75 3
                new PsrAutoloaderLocator(
76 3
                    Psr4Mapping::fromArrayMappings(array_merge_recursive(
77 3
                        [],
78
                        ...array_map(function (array $package) use ($realInstallationPath) : array {
79 3
                            return $this->prefixWithPackagePath(
80 3
                                $this->packageToPsr4AutoloadNamespaces($package),
81
                                $realInstallationPath,
82
                                $package
83
                            );
84 3
                        }, $installed)
85
                    )),
86
                    $astLocator
87
                ),
88 3
                new PsrAutoloaderLocator(
89 3
                    Psr0Mapping::fromArrayMappings(array_merge_recursive(
90 3
                        [],
91
                        ...array_map(function (array $package) use ($realInstallationPath) : array {
92 3
                            return $this->prefixWithPackagePath(
93 3
                                $this->packageToPsr0AutoloadNamespaces($package),
94
                                $realInstallationPath,
95
                                $package
96
                            );
97 3
                        }, $installed)
98
                    )),
99
                    $astLocator
100
                ),
101 3
                new DirectoriesSourceLocator($classMapDirectories, $astLocator),
102
            ],
103
            ...array_map(static function (string $file) use ($astLocator) : array {
104 2
                return [new SingleFileSourceLocator($file, $astLocator)];
105 3
            }, array_merge($classMapFiles, $filePaths))
106
        ));
107
    }
108
109
    /**
110
     * @param array{autoload: array{classmap: array<int, string>, files: array<int, string>, psr-4: array<string, array<int, string>>, psr-0: array<string, array<int, string>>}} $package
111
     *
112
     * @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...
113
     */
114 3
    private function packageToPsr4AutoloadNamespaces(array $package) : array
115
    {
116
        return array_map(static function ($namespacePaths) : array {
117 3
            return (array) $namespacePaths;
118 3
        }, $package['autoload']['psr-4'] ?? []);
119
    }
120
121
    /**
122
     * @param array{autoload: array{classmap: array<int, string>, files: array<int, string>, psr-4: array<string, array<int, string>>, psr-0: array<string, array<int, string>>}} $package
123
     *
124
     * @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...
125
     */
126 3
    private function packageToPsr0AutoloadNamespaces(array $package) : array
127
    {
128
        return array_map(static function ($namespacePaths) : array {
129 3
            return (array) $namespacePaths;
130 3
        }, $package['autoload']['psr-0'] ?? []);
131
    }
132
133
    /**
134
     * @param array{autoload: array{classmap: array<int, string>, files: array<int, string>, psr-4: array<string, array<int, string>>, psr-0: array<string, array<int, string>>}} $package
135
     *
136
     * @return array<int, string>
0 ignored issues
show
The doc-type array<int, 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...
137
     */
138 3
    private function packageToClassMapPaths(array $package) : array
139
    {
140 3
        return $package['autoload']['classmap'] ?? [];
141
    }
142
143
    /**
144
     * @param array{autoload: array{classmap: array<int, string>, files: array<int, string>, psr-4: array<string, array<int, string>>, psr-0: array<string, array<int, string>>}} $package
145
     *
146
     * @return array<int, string>
0 ignored issues
show
The doc-type array<int, 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...
147
     */
148 3
    private function packageToFilePaths(array $package) : array
149
    {
150 3
        return $package['autoload']['files'] ?? [];
151
    }
152
153
    /**
154
     * @param array{name: string, autoload: array{classmap: array<int, string>, files: array<int, string>, psr-4: array<string, array<int, string>>, psr-0: array<string, array<int, string>>}} $package
155
     *
156
     * @psalm-param array{name: string} $package
157
     */
158 3
    private function packagePrefixPath(string $trimmedInstallationPath, array $package) : string
159
    {
160 3
        return $trimmedInstallationPath . '/vendor/' . $package['name'] . '/';
161
    }
162
163
    /**
164
     * @param array<int|string, array<string>> $paths
165
     * @param array<string, array<string>>     $package
166
     *
167
     * @return array<int|string, string|array<string>>
0 ignored issues
show
The doc-type array<int|string, could not be parsed: Expected ">" at position 7, 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...
168
     *
169
     * @psalm-param array{name: string} $package
170
     */
171 3 View Code Duplication
    private function prefixWithPackagePath(array $paths, string $trimmedInstallationPath, array $package) : array
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...
172
    {
173 3
        $prefix = $this->packagePrefixPath($trimmedInstallationPath, $package);
174
175
        return array_map(function (array $paths) use ($prefix) : array {
176 3
            return $this->prefixPaths($paths, $prefix);
177 3
        }, $paths);
178
    }
179
180
    /**
181
     * @param array<int|string, string> $paths
182
     *
183
     * @return array<int|string, string>
0 ignored issues
show
The doc-type array<int|string, could not be parsed: Expected ">" at position 7, 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...
184
     */
185 3
    private function prefixPaths(array $paths, string $prefix) : array
186
    {
187
        return array_map(static function (string $path) use ($prefix) {
188 3
            return $prefix . $path;
189 3
        }, $paths);
190
    }
191
}
192