diff --git a/src/PhpDoc/DefaultStubFilesProvider.php b/src/PhpDoc/DefaultStubFilesProvider.php index 6e13e3944d..126d88e028 100644 --- a/src/PhpDoc/DefaultStubFilesProvider.php +++ b/src/PhpDoc/DefaultStubFilesProvider.php @@ -10,7 +10,9 @@ use function array_filter; use function array_map; use function array_values; +use function dirname; use function str_contains; +use function str_starts_with; #[AutowiredService(as: StubFilesProvider::class)] final class DefaultStubFilesProvider implements StubFilesProvider @@ -60,7 +62,13 @@ public function getProjectStubFiles(): array return $this->cachedProjectFiles; } + $phpstanStubsDirectory = $this->fileHelper->normalizePath(dirname(dirname(__DIR__)) . '/stubs'); + $filteredStubFiles = $this->getStubFiles(); + $filteredStubFiles = array_filter( + $filteredStubFiles, + static fn (string $file): bool => !str_starts_with($file, $phpstanStubsDirectory) + ); foreach ($this->composerAutoloaderProjectPaths as $composerAutoloaderProjectPath) { $composerConfig = ComposerHelper::getComposerConfig($composerAutoloaderProjectPath); if ($composerConfig === null) { diff --git a/tests/PHPStan/PhpDoc/DefaultStubFilesProviderTest.php b/tests/PHPStan/PhpDoc/DefaultStubFilesProviderTest.php index 9fb8d33c67..9e6875fb9e 100644 --- a/tests/PHPStan/PhpDoc/DefaultStubFilesProviderTest.php +++ b/tests/PHPStan/PhpDoc/DefaultStubFilesProviderTest.php @@ -5,7 +5,9 @@ use Override; use PHPStan\File\FileHelper; use PHPStan\Testing\PHPStanTestCase; +use function dirname; use function sprintf; +use const DIRECTORY_SEPARATOR; class DefaultStubFilesProviderTest extends PHPStanTestCase { @@ -30,10 +32,15 @@ public function testGetStubFiles(): void public function testGetProjectStubFiles(): void { $thirdPartyStubFile = sprintf('%s/vendor/thirdpartyStub.stub', $this->currentWorkingDirectory); - $defaultStubFilesProvider = $this->createDefaultStubFilesProvider(['/projectStub.stub', $thirdPartyStubFile]); + $firstPartyStubFile = dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'spl.stub'; + $defaultStubFilesProvider = $this->createDefaultStubFilesProvider(['/projectStub.stub', $thirdPartyStubFile, $firstPartyStubFile]); $projectStubFiles = $defaultStubFilesProvider->getProjectStubFiles(); $this->assertContains('/projectStub.stub', $projectStubFiles); $this->assertNotContains($thirdPartyStubFile, $projectStubFiles); + $this->assertNotContains($firstPartyStubFile, $projectStubFiles); + + $fileHelper = new FileHelper(__DIR__); + $this->assertNotContains($fileHelper->normalizePath($firstPartyStubFile), $projectStubFiles); } public function testGetProjectStubFilesWhenPathContainsWindowsSeparator(): void