[Stubs] Fix Regression Scoped autoload introduced in 0.11.38 (#484)

* [Stubs] Fix Regression Scoped autoload introduced in 0.11.38

* phpstan

* comment
This commit is contained in:
Abdul Malik Ikhsan 2021-07-23 00:05:10 +07:00 committed by GitHub
parent 17db511043
commit 99e5c8add0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,11 +44,8 @@ final class PHPStanStubLoader
}
foreach (self::STUBS as $stub) {
// this is to handle phpstan's stubs got from phpstan-extracted instead of the .phar.
$path = sprintf('%s/phpstan/phpstan-extracted/stubs/runtime/%s', $vendorPath, $stub);
$isExists = file_exists($path);
if (! $isExists) {
$path = $this->getStubPath($vendorPath, $stub);
if ($path === null) {
continue 2;
}
@ -61,4 +58,23 @@ final class PHPStanStubLoader
break;
}
}
private function getStubPath(string $vendorPath, string $stub): ?string
{
// @todo: need to be switched when phpstan-extracted used after scoped php 7.0 works
$path = sprintf('phar://%s/phpstan/phpstan/phpstan.phar/stubs/runtime/%s', $vendorPath, $stub);
$isExists = file_exists($path);
if (! $isExists) {
// this is to handle phpstan's stubs got from phpstan-extracted instead of the .phar when exists after scoped php 7.0 applied
$path = sprintf('%s/phpstan/phpstan-extracted/stubs/runtime/%s', $vendorPath, $stub);
$isExists = file_exists($path);
}
if ($isExists) {
return $path;
}
return null;
}
}