Skip to content

Commit 7bdfdd4

Browse files
committed
It is not FileExcluder job to exclude stub files
1 parent 8ef5163 commit 7bdfdd4

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/Command/CommandHelper.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@
2020
use PHPStan\DependencyInjection\InvalidIgnoredErrorPatternsException;
2121
use PHPStan\DependencyInjection\LoaderFactory;
2222
use PHPStan\ExtensionInstaller\GeneratedConfig;
23+
use PHPStan\File\FileExcluder;
2324
use PHPStan\File\FileFinder;
2425
use PHPStan\File\FileHelper;
26+
use PHPStan\PhpDoc\StubFilesProvider;
2527
use PHPStan\ShouldNotHappenException;
2628
use ReflectionClass;
2729
use Symfony\Component\Console\Input\InputInterface;
2830
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2931
use Symfony\Component\Console\Output\OutputInterface;
3032
use Throwable;
33+
use function array_filter;
3134
use function array_key_exists;
3235
use function array_map;
36+
use function array_values;
3337
use function class_exists;
3438
use function count;
3539
use function dirname;
@@ -467,13 +471,20 @@ public static function begin(
467471

468472
$pathRoutingParser = $container->getService('pathRoutingParser');
469473

474+
/** @var StubFilesProvider $stubFilesProvider */
475+
$stubFilesProvider = $container->getByType(StubFilesProvider::class);
476+
470477
/** @var Closure(): array{string[], bool} $filesCallback */
471-
$filesCallback = static function () use ($fileFinder, $pathRoutingParser, $paths): array {
478+
$filesCallback = static function () use ($currentWorkingDirectoryFileHelper, $stubFilesProvider, $fileFinder, $pathRoutingParser, $paths): array {
472479
$fileFinderResult = $fileFinder->findFiles($paths);
473480
$files = $fileFinderResult->getFiles();
474481

475482
$pathRoutingParser->setAnalysedFiles($files);
476483

484+
$stubFilesExcluder = new FileExcluder($currentWorkingDirectoryFileHelper, $stubFilesProvider->getProjectStubFiles());
485+
486+
$files = array_values(array_filter($files, static fn (string $file) => !$stubFilesExcluder->isExcludedFromAnalysing($file)));
487+
477488
return [$files, $fileFinderResult->isOnlyFiles()];
478489
};
479490

src/File/FileExcluderFactory.php

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

33
namespace PHPStan\File;
44

5-
use PHPStan\PhpDoc\StubFilesProvider;
65
use function array_key_exists;
76
use function array_merge;
87
use function array_unique;
@@ -17,7 +16,6 @@ class FileExcluderFactory
1716
*/
1817
public function __construct(
1918
private FileExcluderRawFactory $fileExcluderRawFactory,
20-
private StubFilesProvider $stubFilesProvider,
2119
private array $obsoleteExcludesAnalyse,
2220
private ?array $excludePaths,
2321
)
@@ -27,7 +25,7 @@ public function __construct(
2725
public function createAnalyseFileExcluder(): FileExcluder
2826
{
2927
if ($this->excludePaths === null) {
30-
return $this->fileExcluderRawFactory->create(array_merge($this->obsoleteExcludesAnalyse, $this->stubFilesProvider->getStubFiles()));
28+
return $this->fileExcluderRawFactory->create($this->obsoleteExcludesAnalyse);
3129
}
3230

3331
$paths = [];
@@ -38,7 +36,7 @@ public function createAnalyseFileExcluder(): FileExcluder
3836
$paths = array_merge($paths, $this->excludePaths['analyseAndScan']);
3937
}
4038

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

4442
public function createScanFileExcluder(): FileExcluder

0 commit comments

Comments
 (0)