diff --git a/src/PhpDoc/DefaultStubFilesProvider.php b/src/PhpDoc/DefaultStubFilesProvider.php index f694dcf9c3..a290f472b9 100644 --- a/src/PhpDoc/DefaultStubFilesProvider.php +++ b/src/PhpDoc/DefaultStubFilesProvider.php @@ -8,8 +8,11 @@ use PHPStan\Internal\ComposerHelper; use function array_filter; use function array_values; +use function dirname; use function str_contains; +use function str_starts_with; use function strtr; +use const DIRECTORY_SEPARATOR; #[AutowiredService(as: StubFilesProvider::class)] final class DefaultStubFilesProvider implements StubFilesProvider @@ -59,6 +62,10 @@ public function getProjectStubFiles(): array } $filteredStubFiles = $this->getStubFiles(); + $filteredStubFiles = array_filter( + $filteredStubFiles, + static fn (string $file): bool => !str_starts_with($file, dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'stubs') + ); 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 90635f3e69..02a4ac6358 100644 --- a/tests/PHPStan/PhpDoc/DefaultStubFilesProviderTest.php +++ b/tests/PHPStan/PhpDoc/DefaultStubFilesProviderTest.php @@ -4,7 +4,9 @@ use Override; use PHPStan\Testing\PHPStanTestCase; +use function dirname; use function sprintf; +use const DIRECTORY_SEPARATOR; class DefaultStubFilesProviderTest extends PHPStanTestCase { @@ -29,10 +31,12 @@ 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); } public function testGetProjectStubFilesWhenPathContainsWindowsSeparator(): void