From 6d3efd5be7ab2de0a25aebabddb26c497611d4fb Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 26 Mar 2023 15:43:02 +0700 Subject: [PATCH] [Core] Set configured file extensions to analyzed files for NodeScopeResolver (#3522) * [Core] Set configured file extensions to analyzed files for NodeScopeResolver * Final touch: rename variable * Final touch: rename variable * Final touch: clean up --- packages/Parallel/WorkerRunner.php | 2 +- src/Application/ApplicationFileProcessor.php | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/Parallel/WorkerRunner.php b/packages/Parallel/WorkerRunner.php index 701268c0981..4b177fc2643 100644 --- a/packages/Parallel/WorkerRunner.php +++ b/packages/Parallel/WorkerRunner.php @@ -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 { diff --git a/src/Application/ApplicationFileProcessor.php b/src/Application/ApplicationFileProcessor.php index f3a0fea300c..d670b5a802f 100644 --- a/src/Application/ApplicationFileProcessor.php +++ b/src/Application/ApplicationFileProcessor.php @@ -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); @@ -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); } /**