diff --git a/bin/phpstan b/bin/phpstan index a5837566a5..41969b6d7f 100755 --- a/bin/phpstan +++ b/bin/phpstan @@ -14,10 +14,8 @@ use PHPStan\Command\DumpDependenciesCommand; $autoloaderInWorkingDirectory = getcwd() . '/vendor/autoload.php'; $composerAutoloaderProjectPaths = []; if (is_file($autoloaderInWorkingDirectory)) { - $composerJsonPath = dirname($autoloaderInWorkingDirectory, 2); - if (is_file($composerJsonPath . '/composer.json')) { - $composerAutoloaderProjectPaths[] = $composerJsonPath; - } + $composerAutoloaderProjectPaths[] = dirname($autoloaderInWorkingDirectory, 2); + require_once $autoloaderInWorkingDirectory; } @@ -25,29 +23,23 @@ use PHPStan\Command\DumpDependenciesCommand; $path = dirname(__DIR__) . $file; if (!extension_loaded('phar')) { if (is_file($path)) { - $composerJsonPath = dirname($path, 2); - if (is_file($composerJsonPath . '/composer.json')) { - $composerAutoloaderProjectPaths[] = $composerJsonPath; - } + $composerAutoloaderProjectPaths[] = dirname($path, 2); + require_once $path; } } else { $pharPath = \Phar::running(false); if ($pharPath === '') { if (is_file($path)) { - $composerJsonPath = dirname($path, 2); - if (is_file($composerJsonPath . '/composer.json')) { - $composerAutoloaderProjectPaths[] = $composerJsonPath; - } + $composerAutoloaderProjectPaths[] = dirname($path, 2); + require_once $path; } } else { $path = dirname($pharPath) . $file; if (is_file($path)) { - $composerJsonPath = dirname($path, 2); - if (is_file($composerJsonPath . '/composer.json')) { - $composerAutoloaderProjectPaths[] = $composerJsonPath; - } + $composerAutoloaderProjectPaths[] = dirname($path, 2); + require_once $path; } } diff --git a/src/Reflection/BetterReflection/BetterReflectionSourceLocatorFactory.php b/src/Reflection/BetterReflection/BetterReflectionSourceLocatorFactory.php index 7d39f72467..e8887481f9 100644 --- a/src/Reflection/BetterReflection/BetterReflectionSourceLocatorFactory.php +++ b/src/Reflection/BetterReflection/BetterReflectionSourceLocatorFactory.php @@ -95,7 +95,11 @@ public function create(): SourceLocator $locators = []; foreach ($this->composerAutoloaderProjectPaths as $composerAutoloaderProjectPath) { - $locators[] = $this->composerJsonAndInstalledJsonSourceLocatorMaker->create($composerAutoloaderProjectPath); + $locator = $this->composerJsonAndInstalledJsonSourceLocatorMaker->create($composerAutoloaderProjectPath); + if ($locator === null) { + continue; + } + $locators[] = $locator; } if ($this->enableScanningPaths) { diff --git a/src/Reflection/BetterReflection/SourceLocator/ComposerJsonAndInstalledJsonSourceLocatorMaker.php b/src/Reflection/BetterReflection/SourceLocator/ComposerJsonAndInstalledJsonSourceLocatorMaker.php index 1da1ad1f4c..3cb7a7410c 100644 --- a/src/Reflection/BetterReflection/SourceLocator/ComposerJsonAndInstalledJsonSourceLocatorMaker.php +++ b/src/Reflection/BetterReflection/SourceLocator/ComposerJsonAndInstalledJsonSourceLocatorMaker.php @@ -37,10 +37,16 @@ public function __construct( $this->enableScanningPaths = $enableScanningPaths; } - public function create(string $installationPath): SourceLocator + public function create(string $installationPath): ?SourceLocator { $composerJsonPath = $installationPath . '/composer.json'; + if (!is_file($composerJsonPath)) { + return null; + } $installedJsonPath = $installationPath . '/vendor/composer/installed.json'; + if (!is_file($installedJsonPath)) { + return null; + } $composerJsonContents = FileReader::read($composerJsonPath); $composer = Json::decode($composerJsonContents, Json::FORCE_ARRAY);