Skip to content

Commit

Permalink
Skip Composer loader directories where installed.json is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 6, 2020
1 parent 9eedeac commit e4fe64c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
24 changes: 8 additions & 16 deletions bin/phpstan
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,32 @@ 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;
}

$autoloadProjectAutoloaderFile = function (string $file) use (&$composerAutoloaderProjectPaths): void {
$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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e4fe64c

Please sign in to comment.