diff --git a/src/Analyser/IgnoredError.php b/src/Analyser/IgnoredError.php index 52bacade42..09a2c6225c 100644 --- a/src/Analyser/IgnoredError.php +++ b/src/Analyser/IgnoredError.php @@ -5,7 +5,6 @@ use Nette\Utils\Strings; use PHPStan\File\FileExcluder; use PHPStan\File\FileHelper; -use PHPStan\PhpDoc\EmptyStubFilesProvider; use function count; use function implode; use function is_array; @@ -60,7 +59,7 @@ public static function shouldIgnore( return false; } - $fileExcluder = new FileExcluder($fileHelper, new EmptyStubFilesProvider(), [$path]); + $fileExcluder = new FileExcluder($fileHelper, [$path]); $isExcluded = $fileExcluder->isExcludedFromAnalysing($error->getFilePath()); if (!$isExcluded && $error->getTraitFilePath() !== null) { return $fileExcluder->isExcludedFromAnalysing($error->getTraitFilePath()); diff --git a/src/File/FileExcluder.php b/src/File/FileExcluder.php index ff4f63b613..e44dedee53 100644 --- a/src/File/FileExcluder.php +++ b/src/File/FileExcluder.php @@ -2,8 +2,6 @@ namespace PHPStan\File; -use PHPStan\PhpDoc\StubFilesProvider; -use function array_merge; use function fnmatch; use function in_array; use function preg_match; @@ -36,11 +34,10 @@ class FileExcluder */ public function __construct( FileHelper $fileHelper, - StubFilesProvider $stubFilesProvider, array $analyseExcludes, ) { - foreach (array_merge($analyseExcludes, $stubFilesProvider->getStubFiles()) as $exclude) { + foreach ($analyseExcludes as $exclude) { $len = strlen($exclude); $trailingDirSeparator = ($len > 0 && in_array($exclude[$len - 1], ['\\', '/'], true)); diff --git a/src/File/FileExcluderFactory.php b/src/File/FileExcluderFactory.php index 26976a3dfb..d5274001b9 100644 --- a/src/File/FileExcluderFactory.php +++ b/src/File/FileExcluderFactory.php @@ -2,6 +2,7 @@ namespace PHPStan\File; +use PHPStan\PhpDoc\StubFilesProvider; use function array_key_exists; use function array_merge; use function array_unique; @@ -16,6 +17,7 @@ class FileExcluderFactory */ public function __construct( private FileExcluderRawFactory $fileExcluderRawFactory, + private StubFilesProvider $stubFilesProvider, private array $obsoleteExcludesAnalyse, private ?array $excludePaths, ) @@ -25,7 +27,7 @@ public function __construct( public function createAnalyseFileExcluder(): FileExcluder { if ($this->excludePaths === null) { - return $this->fileExcluderRawFactory->create($this->obsoleteExcludesAnalyse); + return $this->fileExcluderRawFactory->create(array_merge($this->obsoleteExcludesAnalyse, $this->stubFilesProvider->getStubFiles())); } $paths = []; @@ -36,7 +38,7 @@ public function createAnalyseFileExcluder(): FileExcluder $paths = array_merge($paths, $this->excludePaths['analyseAndScan']); } - return $this->fileExcluderRawFactory->create(array_values(array_unique($paths))); + return $this->fileExcluderRawFactory->create(array_merge(array_values(array_unique($paths)), $this->stubFilesProvider->getStubFiles())); } public function createScanFileExcluder(): FileExcluder diff --git a/src/PhpDoc/EmptyStubFilesProvider.php b/src/PhpDoc/EmptyStubFilesProvider.php deleted file mode 100644 index 0f5bb2124d..0000000000 --- a/src/PhpDoc/EmptyStubFilesProvider.php +++ /dev/null @@ -1,18 +0,0 @@ -skipIfNotOnWindows(); - $fileExcluder = new FileExcluder($this->getFileHelper(), new EmptyStubFilesProvider(), $analyseExcludes); + $fileExcluder = new FileExcluder($this->getFileHelper(), $analyseExcludes); $this->assertSame($isExcluded, $fileExcluder->isExcludedFromAnalysing($filePath)); } @@ -128,7 +127,7 @@ public function testFilesAreExcludedFromAnalysingOnUnix( { $this->skipIfNotOnUnix(); - $fileExcluder = new FileExcluder($this->getFileHelper(), new EmptyStubFilesProvider(), $analyseExcludes); + $fileExcluder = new FileExcluder($this->getFileHelper(), $analyseExcludes); $this->assertSame($isExcluded, $fileExcluder->isExcludedFromAnalysing($filePath)); }