Skip to content

Commit e4fe64c

Browse files
committed
Skip Composer loader directories where installed.json is not present
1 parent 9eedeac commit e4fe64c

3 files changed

Lines changed: 20 additions & 18 deletions

File tree

bin/phpstan

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,32 @@ use PHPStan\Command\DumpDependenciesCommand;
1414
$autoloaderInWorkingDirectory = getcwd() . '/vendor/autoload.php';
1515
$composerAutoloaderProjectPaths = [];
1616
if (is_file($autoloaderInWorkingDirectory)) {
17-
$composerJsonPath = dirname($autoloaderInWorkingDirectory, 2);
18-
if (is_file($composerJsonPath . '/composer.json')) {
19-
$composerAutoloaderProjectPaths[] = $composerJsonPath;
20-
}
17+
$composerAutoloaderProjectPaths[] = dirname($autoloaderInWorkingDirectory, 2);
18+
2119
require_once $autoloaderInWorkingDirectory;
2220
}
2321

2422
$autoloadProjectAutoloaderFile = function (string $file) use (&$composerAutoloaderProjectPaths): void {
2523
$path = dirname(__DIR__) . $file;
2624
if (!extension_loaded('phar')) {
2725
if (is_file($path)) {
28-
$composerJsonPath = dirname($path, 2);
29-
if (is_file($composerJsonPath . '/composer.json')) {
30-
$composerAutoloaderProjectPaths[] = $composerJsonPath;
31-
}
26+
$composerAutoloaderProjectPaths[] = dirname($path, 2);
27+
3228
require_once $path;
3329
}
3430
} else {
3531
$pharPath = \Phar::running(false);
3632
if ($pharPath === '') {
3733
if (is_file($path)) {
38-
$composerJsonPath = dirname($path, 2);
39-
if (is_file($composerJsonPath . '/composer.json')) {
40-
$composerAutoloaderProjectPaths[] = $composerJsonPath;
41-
}
34+
$composerAutoloaderProjectPaths[] = dirname($path, 2);
35+
4236
require_once $path;
4337
}
4438
} else {
4539
$path = dirname($pharPath) . $file;
4640
if (is_file($path)) {
47-
$composerJsonPath = dirname($path, 2);
48-
if (is_file($composerJsonPath . '/composer.json')) {
49-
$composerAutoloaderProjectPaths[] = $composerJsonPath;
50-
}
41+
$composerAutoloaderProjectPaths[] = dirname($path, 2);
42+
5143
require_once $path;
5244
}
5345
}

src/Reflection/BetterReflection/BetterReflectionSourceLocatorFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ public function create(): SourceLocator
9595
$locators = [];
9696

9797
foreach ($this->composerAutoloaderProjectPaths as $composerAutoloaderProjectPath) {
98-
$locators[] = $this->composerJsonAndInstalledJsonSourceLocatorMaker->create($composerAutoloaderProjectPath);
98+
$locator = $this->composerJsonAndInstalledJsonSourceLocatorMaker->create($composerAutoloaderProjectPath);
99+
if ($locator === null) {
100+
continue;
101+
}
102+
$locators[] = $locator;
99103
}
100104

101105
if ($this->enableScanningPaths) {

src/Reflection/BetterReflection/SourceLocator/ComposerJsonAndInstalledJsonSourceLocatorMaker.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,16 @@ public function __construct(
3737
$this->enableScanningPaths = $enableScanningPaths;
3838
}
3939

40-
public function create(string $installationPath): SourceLocator
40+
public function create(string $installationPath): ?SourceLocator
4141
{
4242
$composerJsonPath = $installationPath . '/composer.json';
43+
if (!is_file($composerJsonPath)) {
44+
return null;
45+
}
4346
$installedJsonPath = $installationPath . '/vendor/composer/installed.json';
47+
if (!is_file($installedJsonPath)) {
48+
return null;
49+
}
4450

4551
$composerJsonContents = FileReader::read($composerJsonPath);
4652
$composer = Json::decode($composerJsonContents, Json::FORCE_ARRAY);

0 commit comments

Comments
 (0)