Skip to content

Commit

Permalink
It is not FileExcluder job to exclude stub files
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 12, 2023
1 parent 8ef5163 commit 7bdfdd4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 12 additions & 1 deletion src/Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@
use PHPStan\DependencyInjection\InvalidIgnoredErrorPatternsException;
use PHPStan\DependencyInjection\LoaderFactory;
use PHPStan\ExtensionInstaller\GeneratedConfig;
use PHPStan\File\FileExcluder;
use PHPStan\File\FileFinder;
use PHPStan\File\FileHelper;
use PHPStan\PhpDoc\StubFilesProvider;
use PHPStan\ShouldNotHappenException;
use ReflectionClass;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;
use function array_filter;
use function array_key_exists;
use function array_map;
use function array_values;
use function class_exists;
use function count;
use function dirname;
Expand Down Expand Up @@ -467,13 +471,20 @@ public static function begin(

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

/** @var StubFilesProvider $stubFilesProvider */
$stubFilesProvider = $container->getByType(StubFilesProvider::class);

/** @var Closure(): array{string[], bool} $filesCallback */
$filesCallback = static function () use ($fileFinder, $pathRoutingParser, $paths): array {
$filesCallback = static function () use ($currentWorkingDirectoryFileHelper, $stubFilesProvider, $fileFinder, $pathRoutingParser, $paths): array {
$fileFinderResult = $fileFinder->findFiles($paths);
$files = $fileFinderResult->getFiles();

$pathRoutingParser->setAnalysedFiles($files);

$stubFilesExcluder = new FileExcluder($currentWorkingDirectoryFileHelper, $stubFilesProvider->getProjectStubFiles());

$files = array_values(array_filter($files, static fn (string $file) => !$stubFilesExcluder->isExcludedFromAnalysing($file)));

return [$files, $fileFinderResult->isOnlyFiles()];
};

Expand Down
6 changes: 2 additions & 4 deletions src/File/FileExcluderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace PHPStan\File;

use PHPStan\PhpDoc\StubFilesProvider;
use function array_key_exists;
use function array_merge;
use function array_unique;
Expand All @@ -17,7 +16,6 @@ class FileExcluderFactory
*/
public function __construct(
private FileExcluderRawFactory $fileExcluderRawFactory,
private StubFilesProvider $stubFilesProvider,
private array $obsoleteExcludesAnalyse,
private ?array $excludePaths,
)
Expand All @@ -27,7 +25,7 @@ public function __construct(
public function createAnalyseFileExcluder(): FileExcluder
{
if ($this->excludePaths === null) {
return $this->fileExcluderRawFactory->create(array_merge($this->obsoleteExcludesAnalyse, $this->stubFilesProvider->getStubFiles()));
return $this->fileExcluderRawFactory->create($this->obsoleteExcludesAnalyse);
}

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

return $this->fileExcluderRawFactory->create(array_merge(array_values(array_unique($paths)), $this->stubFilesProvider->getStubFiles()));
return $this->fileExcluderRawFactory->create(array_values(array_unique($paths)));
}

public function createScanFileExcluder(): FileExcluder
Expand Down

0 comments on commit 7bdfdd4

Please sign in to comment.