Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/PhpDoc/DefaultStubFilesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion tests/PHPStan/PhpDoc/DefaultStubFilesProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down
Loading