Skip to content

Exclude first-party stubs from validation #4190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.1.x
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions src/PhpDoc/DefaultStubFilesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion tests/PHPStan/PhpDoc/DefaultStubFilesProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Override;
use PHPStan\Testing\PHPStanTestCase;
use function dirname;
use function sprintf;
use const DIRECTORY_SEPARATOR;

class DefaultStubFilesProviderTest extends PHPStanTestCase
{
Expand All @@ -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
Expand Down
Loading