Skip to content

Commit

Permalink
[Core] Make consistent only setAnalysedFiles() from PHPStan NodeScope…
Browse files Browse the repository at this point in the history
…Resolver in both parallel and non-parallel for .php files (#3221)

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Dec 21, 2022
1 parent c80cd6f commit b1fff57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 35 deletions.
6 changes: 3 additions & 3 deletions packages/Parallel/WorkerRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Clue\React\NDJson\Decoder;
use Clue\React\NDJson\Encoder;
use Nette\Utils\FileSystem;
use PHPStan\Analyser\NodeScopeResolver;
use Rector\Core\Application\ApplicationFileProcessor;
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesProcessor;
use Rector\Core\Console\Style\RectorConsoleOutputStyle;
use Rector\Core\Contract\Processor\FileProcessorInterface;
Expand Down Expand Up @@ -37,10 +37,10 @@ final class WorkerRunner
public function __construct(
private readonly ArrayParametersMerger $arrayParametersMerger,
private readonly CurrentFileProvider $currentFileProvider,
private readonly NodeScopeResolver $nodeScopeResolver,
private readonly DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator,
private readonly RectorConsoleOutputStyle $rectorConsoleOutputStyle,
private readonly RemovedAndAddedFilesProcessor $removedAndAddedFilesProcessor,
private readonly ApplicationFileProcessor $applicationFileProcessor,
private readonly array $fileProcessors = []
) {
}
Expand Down 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->nodeScopeResolver->setAnalysedFiles($filePaths);
$this->applicationFileProcessor->configurePHPStanNodeScopeResolver($filePaths);

foreach ($filePaths as $filePath) {
try {
Expand Down
45 changes: 13 additions & 32 deletions src/Application/ApplicationFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Symplify\EasyParallel\CpuCoreCountProvider;
use Symplify\EasyParallel\Exception\ParallelShouldNotHappenException;
use Symplify\EasyParallel\ScheduleFactory;
use Webmozart\Assert\Assert;

final class ApplicationFileProcessor
{
Expand Down Expand Up @@ -81,7 +80,7 @@ public function run(Configuration $configuration, InputInterface $input): array
$files = $this->fileFactory->createFromPaths($fileInfos);

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

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

Expand Down Expand Up @@ -139,6 +138,18 @@ public function processFiles(array $files, Configuration $configuration): array
return $systemErrorsAndFileDiffs;
}

/**
* @param string[] $filePaths
*/
public function configurePHPStanNodeScopeResolver(array $filePaths): void
{
$phpFilePaths = array_filter(
$filePaths,
static fn (string $filePath): bool => str_ends_with($filePath, '.php')
);
$this->nodeScopeResolver->setAnalysedFiles($phpFilePaths);
}

/**
* @param File[] $files
*/
Expand Down Expand Up @@ -260,34 +271,4 @@ private function resolveCalledRectorBinary(): ?string

return $potentialEcsBinaryPath;
}

/**
* @param File[] $files
*/
private function configurePHPStanNodeScopeResolver(array $files): void
{
$filePaths = $this->resolvePhpFilePaths($files);
$this->nodeScopeResolver->setAnalysedFiles($filePaths);
}

/**
* @param File[] $files
* @return string[]
*/
private function resolvePhpFilePaths(array $files): array
{
Assert::allIsAOf($files, File::class);

$phpFilePaths = [];

foreach ($files as $file) {
$filePath = $file->getFilePath();

if (\str_ends_with($filePath, '.php')) {
$phpFilePaths[] = $filePath;
}
}

return $phpFilePaths;
}
}

0 comments on commit b1fff57

Please sign in to comment.