Skip to content

Commit

Permalink
Stub validator - PHPStan classes are known without extra stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 20, 2023
1 parent 992db25 commit d004c23
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/PhpDoc/StubSourceLocatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
use PHPStan\BetterReflection\SourceLocator\Ast\Locator;
use PHPStan\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber;
use PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
use PHPStan\BetterReflection\SourceLocator\Type\Composer\Psr\Psr4Mapping;
use PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator;
use PHPStan\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator;
use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator;
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedPsrAutoloaderLocatorFactory;
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocatorRepository;
use function dirname;

class StubSourceLocatorFactory
{
Expand All @@ -18,6 +21,7 @@ public function __construct(
private Parser $php8Parser,
private PhpStormStubsSourceStubber $phpStormStubsSourceStubber,
private OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository,
private OptimizedPsrAutoloaderLocatorFactory $optimizedPsrAutoloaderLocatorFactory,
private StubFilesProvider $stubFilesProvider,
)
{
Expand All @@ -31,6 +35,12 @@ public function create(): SourceLocator
$locators[] = $this->optimizedSingleFileSourceLocatorRepository->getOrCreate($stubFile);
}

$locators[] = $this->optimizedPsrAutoloaderLocatorFactory->create(
Psr4Mapping::fromArrayMappings([
'PHPStan\\' => [dirname(__DIR__) . '/'],
]),
);

$locators[] = new PhpInternalSourceLocator($astPhp8Locator, $this->phpStormStubsSourceStubber);

return new MemoizingSourceLocator(new AggregateSourceLocator($locators));
Expand Down

0 comments on commit d004c23

Please sign in to comment.