Skip to content

Commit 8ef5163

Browse files
committed
Only analysis FileExcluder excludes stub files
This will allow us to use ReflectionProvider in StubFilesExtension
1 parent a2a733b commit 8ef5163

File tree

5 files changed

+8
-29
lines changed

5 files changed

+8
-29
lines changed

src/Analyser/IgnoredError.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Nette\Utils\Strings;
66
use PHPStan\File\FileExcluder;
77
use PHPStan\File\FileHelper;
8-
use PHPStan\PhpDoc\EmptyStubFilesProvider;
98
use function count;
109
use function implode;
1110
use function is_array;
@@ -60,7 +59,7 @@ public static function shouldIgnore(
6059
return false;
6160
}
6261

63-
$fileExcluder = new FileExcluder($fileHelper, new EmptyStubFilesProvider(), [$path]);
62+
$fileExcluder = new FileExcluder($fileHelper, [$path]);
6463
$isExcluded = $fileExcluder->isExcludedFromAnalysing($error->getFilePath());
6564
if (!$isExcluded && $error->getTraitFilePath() !== null) {
6665
return $fileExcluder->isExcludedFromAnalysing($error->getTraitFilePath());

src/File/FileExcluder.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace PHPStan\File;
44

5-
use PHPStan\PhpDoc\StubFilesProvider;
6-
use function array_merge;
75
use function fnmatch;
86
use function in_array;
97
use function preg_match;
@@ -36,11 +34,10 @@ class FileExcluder
3634
*/
3735
public function __construct(
3836
FileHelper $fileHelper,
39-
StubFilesProvider $stubFilesProvider,
4037
array $analyseExcludes,
4138
)
4239
{
43-
foreach (array_merge($analyseExcludes, $stubFilesProvider->getStubFiles()) as $exclude) {
40+
foreach ($analyseExcludes as $exclude) {
4441
$len = strlen($exclude);
4542
$trailingDirSeparator = ($len > 0 && in_array($exclude[$len - 1], ['\\', '/'], true));
4643

src/File/FileExcluderFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\File;
44

5+
use PHPStan\PhpDoc\StubFilesProvider;
56
use function array_key_exists;
67
use function array_merge;
78
use function array_unique;
@@ -16,6 +17,7 @@ class FileExcluderFactory
1617
*/
1718
public function __construct(
1819
private FileExcluderRawFactory $fileExcluderRawFactory,
20+
private StubFilesProvider $stubFilesProvider,
1921
private array $obsoleteExcludesAnalyse,
2022
private ?array $excludePaths,
2123
)
@@ -25,7 +27,7 @@ public function __construct(
2527
public function createAnalyseFileExcluder(): FileExcluder
2628
{
2729
if ($this->excludePaths === null) {
28-
return $this->fileExcluderRawFactory->create($this->obsoleteExcludesAnalyse);
30+
return $this->fileExcluderRawFactory->create(array_merge($this->obsoleteExcludesAnalyse, $this->stubFilesProvider->getStubFiles()));
2931
}
3032

3133
$paths = [];
@@ -36,7 +38,7 @@ public function createAnalyseFileExcluder(): FileExcluder
3638
$paths = array_merge($paths, $this->excludePaths['analyseAndScan']);
3739
}
3840

39-
return $this->fileExcluderRawFactory->create(array_values(array_unique($paths)));
41+
return $this->fileExcluderRawFactory->create(array_merge(array_values(array_unique($paths)), $this->stubFilesProvider->getStubFiles()));
4042
}
4143

4244
public function createScanFileExcluder(): FileExcluder

src/PhpDoc/EmptyStubFilesProvider.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/PHPStan/File/FileExcluderTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\File;
44

5-
use PHPStan\PhpDoc\EmptyStubFilesProvider;
65
use PHPStan\Testing\PHPStanTestCase;
76

87
class FileExcluderTest extends PHPStanTestCase
@@ -20,7 +19,7 @@ public function testFilesAreExcludedFromAnalysingOnWindows(
2019
{
2120
$this->skipIfNotOnWindows();
2221

23-
$fileExcluder = new FileExcluder($this->getFileHelper(), new EmptyStubFilesProvider(), $analyseExcludes);
22+
$fileExcluder = new FileExcluder($this->getFileHelper(), $analyseExcludes);
2423

2524
$this->assertSame($isExcluded, $fileExcluder->isExcludedFromAnalysing($filePath));
2625
}
@@ -128,7 +127,7 @@ public function testFilesAreExcludedFromAnalysingOnUnix(
128127
{
129128
$this->skipIfNotOnUnix();
130129

131-
$fileExcluder = new FileExcluder($this->getFileHelper(), new EmptyStubFilesProvider(), $analyseExcludes);
130+
$fileExcluder = new FileExcluder($this->getFileHelper(), $analyseExcludes);
132131

133132
$this->assertSame($isExcluded, $fileExcluder->isExcludedFromAnalysing($filePath));
134133
}

0 commit comments

Comments
 (0)