Skip to content

Commit f2839be

Browse files
committed
Exclude first-party stubs from validation
Stub files from vendor directories aren't validated. But the stub files that ship with PHPstan itself weren't excluded, and they were hitting the `checkMissingOverrideMethodAttribute` check. This didn't happen when PHPstan was installed through composer, since then the stub files happened to be in a vendor directory. But it did happen when PHPstan ran as a phar. Resolves phpstan/phpstan#11907.
1 parent 985c791 commit f2839be

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/PhpDoc/DefaultStubFilesProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
use PHPStan\Internal\ComposerHelper;
99
use function array_filter;
1010
use function array_values;
11+
use function dirname;
1112
use function str_contains;
13+
use function str_starts_with;
1214
use function strtr;
15+
use const DIRECTORY_SEPARATOR;
1316

1417
#[AutowiredService(as: StubFilesProvider::class)]
1518
final class DefaultStubFilesProvider implements StubFilesProvider
@@ -59,6 +62,10 @@ public function getProjectStubFiles(): array
5962
}
6063

6164
$filteredStubFiles = $this->getStubFiles();
65+
$filteredStubFiles = array_filter(
66+
$filteredStubFiles,
67+
static fn (string $file): bool => !str_starts_with($file, dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'stubs')
68+
);
6269
foreach ($this->composerAutoloaderProjectPaths as $composerAutoloaderProjectPath) {
6370
$composerConfig = ComposerHelper::getComposerConfig($composerAutoloaderProjectPath);
6471
if ($composerConfig === null) {

tests/PHPStan/PhpDoc/DefaultStubFilesProviderTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Override;
66
use PHPStan\Testing\PHPStanTestCase;
7+
use function dirname;
78
use function sprintf;
89

910
class DefaultStubFilesProviderTest extends PHPStanTestCase
@@ -29,10 +30,12 @@ public function testGetStubFiles(): void
2930
public function testGetProjectStubFiles(): void
3031
{
3132
$thirdPartyStubFile = sprintf('%s/vendor/thirdpartyStub.stub', $this->currentWorkingDirectory);
32-
$defaultStubFilesProvider = $this->createDefaultStubFilesProvider(['/projectStub.stub', $thirdPartyStubFile]);
33+
$firstPartyStubFile = dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'spl.stub';
34+
$defaultStubFilesProvider = $this->createDefaultStubFilesProvider(['/projectStub.stub', $thirdPartyStubFile, $firstPartyStubFile]);
3335
$projectStubFiles = $defaultStubFilesProvider->getProjectStubFiles();
3436
$this->assertContains('/projectStub.stub', $projectStubFiles);
3537
$this->assertNotContains($thirdPartyStubFile, $projectStubFiles);
38+
$this->assertNotContains($firstPartyStubFile, $projectStubFiles);
3639
}
3740

3841
public function testGetProjectStubFilesWhenPathContainsWindowsSeparator(): void

0 commit comments

Comments
 (0)