Skip to content

Commit 39bbdb9

Browse files
canvuralondrejmirtes
authored andcommitted
Filter project stub files
1 parent 42a8b19 commit 39bbdb9

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

conf/config.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ services:
470470
class: PHPStan\PhpDoc\DefaultStubFilesProvider
471471
arguments:
472472
stubFiles: %stubFiles%
473+
currentWorkingDirectory: %currentWorkingDirectory%
473474
autowired:
474475
- PHPStan\PhpDoc\StubFilesProvider
475476

src/Command/AnalyseApplication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function analyse(
6969
$input,
7070
);
7171

72-
$projectStubFiles = $this->stubFilesProvider->getStubFiles();
72+
$projectStubFiles = $this->stubFilesProvider->getProjectStubFiles();
7373

7474
if ($resultCache->isFullAnalysis() && count($projectStubFiles) !== 0) {
7575
$stubErrors = $this->stubValidator->validate($projectStubFiles, $debug);

src/PhpDoc/DefaultStubFilesProvider.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@
33
namespace PHPStan\PhpDoc;
44

55
use PHPStan\DependencyInjection\Container;
6+
use PHPStan\Internal\ComposerHelper;
7+
use function array_filter;
8+
use function strpos;
69

710
class DefaultStubFilesProvider implements StubFilesProvider
811
{
912

1013
/** @var string[]|null */
1114
private ?array $cachedFiles = null;
1215

16+
/** @var string[]|null */
17+
private ?array $cachedProjectFiles = null;
18+
1319
/**
1420
* @param string[] $stubFiles
1521
*/
1622
public function __construct(
1723
private Container $container,
1824
private array $stubFiles,
25+
private string $currentWorkingDirectory,
1926
)
2027
{
2128
}
@@ -37,4 +44,22 @@ public function getStubFiles(): array
3744
return $this->cachedFiles = $files;
3845
}
3946

47+
public function getProjectStubFiles(): array
48+
{
49+
if ($this->cachedProjectFiles !== null) {
50+
return $this->cachedProjectFiles;
51+
}
52+
53+
$composerConfig = ComposerHelper::getComposerConfig($this->currentWorkingDirectory);
54+
55+
if ($composerConfig === null) {
56+
return $this->getStubFiles();
57+
}
58+
59+
return $this->cachedProjectFiles = array_filter(
60+
$this->getStubFiles(),
61+
fn (string $file): bool => strpos($file, ComposerHelper::getVendorDirFromComposerConfig($this->currentWorkingDirectory, $composerConfig)) === false
62+
);
63+
}
64+
4065
}

src/PhpDoc/EmptyStubFilesProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ public function getStubFiles(): array
1010
return [];
1111
}
1212

13+
public function getProjectStubFiles(): array
14+
{
15+
return [];
16+
}
17+
1318
}

src/PhpDoc/StubFilesProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ interface StubFilesProvider
88
/** @return string[] */
99
public function getStubFiles(): array;
1010

11+
/** @return string[] */
12+
public function getProjectStubFiles(): array;
13+
1114
}

0 commit comments

Comments
 (0)