Skip to content

Commit

Permalink
[Core] Set configured file extensions to analyzed files for NodeScope…
Browse files Browse the repository at this point in the history
…Resolver (#3522)

* [Core] Set configured file extensions to analyzed files for NodeScopeResolver

* Final touch: rename variable

* Final touch: rename variable

* Final touch: clean up
  • Loading branch information
samsonasik committed Mar 26, 2023
1 parent ad9b597 commit 6d3efd5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/Parallel/WorkerRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function run(Encoder $encoder, Decoder $decoder, Configuration $configura
$systemErrors = [];

// 1. allow PHPStan to work with static reflection on provided files
$this->applicationFileProcessor->configurePHPStanNodeScopeResolver($filePaths);
$this->applicationFileProcessor->configurePHPStanNodeScopeResolver($filePaths, $configuration);

foreach ($filePaths as $filePath) {
try {
Expand Down
15 changes: 10 additions & 5 deletions src/Application/ApplicationFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function run(Configuration $configuration, InputInterface $input): array
$files = $this->fileFactory->createFromPaths($filePaths);

// 2. PHPStan has to know about all files too
$this->configurePHPStanNodeScopeResolver($filePaths);
$this->configurePHPStanNodeScopeResolver($filePaths, $configuration);

$systemErrorsAndFileDiffs = $this->processFiles($files, $configuration);

Expand Down Expand Up @@ -141,11 +141,16 @@ public function processFiles(array $files, Configuration $configuration): array
/**
* @param string[] $filePaths
*/
public function configurePHPStanNodeScopeResolver(array $filePaths): void
public function configurePHPStanNodeScopeResolver(array $filePaths, Configuration $configuration): void
{
$phpFilter = static fn (string $filePath): bool => str_ends_with($filePath, '.php');
$phpFilePaths = array_filter($filePaths, $phpFilter);
$this->nodeScopeResolver->setAnalysedFiles($phpFilePaths);
$fileExtensions = $configuration->getFileExtensions();
$fileWithExtensionsFilter = static function (string $filePath) use ($fileExtensions): bool {
$filePathExtension = pathinfo($filePath, PATHINFO_EXTENSION);
return in_array($filePathExtension, $fileExtensions, true);
};

$filePaths = array_filter($filePaths, $fileWithExtensionsFilter);
$this->nodeScopeResolver->setAnalysedFiles($filePaths);
}

/**
Expand Down

0 comments on commit 6d3efd5

Please sign in to comment.