Skip to content

Commit ab11d4a

Browse files
phpstan-botclaude
andcommitted
Store processedFiles in AnalysisResult, make analyse() return AnalysisResult again
Move processedFiles from a separate array return value into the AnalysisResult DTO so that AnalyseApplication::analyse() returns AnalysisResult directly instead of array{AnalysisResult, list<string>}. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 880c799 commit ab11d4a

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

src/Command/AnalyseApplication.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public function __construct(
5050
/**
5151
* @param string[] $files
5252
* @param mixed[]|null $projectConfigArray
53-
* @return array{AnalysisResult, list<string>}
5453
*/
5554
public function analyse(
5655
array $files,
@@ -64,7 +63,7 @@ public function analyse(
6463
?string $tmpFile,
6564
?string $insteadOfFile,
6665
InputInterface $input,
67-
): array
66+
): AnalysisResult
6867
{
6968
$isResultCacheUsed = false;
7069
$fileReplacements = [];
@@ -177,22 +176,20 @@ public function analyse(
177176
$savedResultCache = $resultCacheResult->isSaved();
178177
}
179178

180-
return [
181-
new AnalysisResult(
182-
$fileSpecificErrors,
183-
$notFileSpecificErrors,
184-
$internalErrors,
185-
[],
186-
$this->mapCollectedData($collectedData),
187-
$defaultLevelUsed,
188-
$projectConfigFile,
189-
$savedResultCache,
190-
$memoryUsageBytes,
191-
$isResultCacheUsed,
192-
$changedProjectExtensionFilesOutsideOfAnalysedPaths,
193-
),
179+
return new AnalysisResult(
180+
$fileSpecificErrors,
181+
$notFileSpecificErrors,
182+
$internalErrors,
183+
[],
184+
$this->mapCollectedData($collectedData),
185+
$defaultLevelUsed,
186+
$projectConfigFile,
187+
$savedResultCache,
188+
$memoryUsageBytes,
189+
$isResultCacheUsed,
190+
$changedProjectExtensionFilesOutsideOfAnalysedPaths,
194191
$processedFiles,
195-
];
192+
);
196193
}
197194

198195
/**

src/Command/AnalyseCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
341341
}
342342

343343
try {
344-
[$analysisResult, $processedFiles] = $application->analyse(
344+
$analysisResult = $application->analyse(
345345
$files,
346346
$onlyFiles,
347347
$inceptionResult->getStdOutput(),
@@ -459,7 +459,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
459459
}
460460

461461
if ($generateBaselineFile !== null) {
462-
$this->runDiagnoseExtensions($container, $inceptionResult->getErrorOutput(), $processedFiles);
462+
$this->runDiagnoseExtensions($container, $inceptionResult->getErrorOutput(), $analysisResult->getProcessedFiles());
463463
if (count($internalErrorsTuples) > 0) {
464464
foreach ($internalErrorsTuples as [$internalError]) {
465465
$inceptionResult->getStdOutput()->writeLineFormatted($internalError->getMessage());
@@ -493,11 +493,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
493493
$analysisResult->getPeakMemoryUsageBytes(),
494494
$analysisResult->isResultCacheUsed(),
495495
$analysisResult->getChangedProjectExtensionFilesOutsideOfAnalysedPaths(),
496+
$analysisResult->getProcessedFiles(),
496497
);
497498

498499
$exitCode = $errorFormatter->formatErrors($analysisResult, $inceptionResult->getStdOutput());
499500

500-
$this->runDiagnoseExtensions($container, $inceptionResult->getErrorOutput(), $processedFiles);
501+
$this->runDiagnoseExtensions($container, $inceptionResult->getErrorOutput(), $analysisResult->getProcessedFiles());
501502

502503
$errorOutput->writeLineFormatted('⚠️ Result is incomplete because of severe errors. ⚠️');
503504
$errorOutput->writeLineFormatted(' Fix these errors first and then re-run PHPStan');
@@ -649,7 +650,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
649650
}
650651
}
651652

652-
$this->runDiagnoseExtensions($container, $inceptionResult->getErrorOutput(), $processedFiles);
653+
$this->runDiagnoseExtensions($container, $inceptionResult->getErrorOutput(), $analysisResult->getProcessedFiles());
653654

654655
return $inceptionResult->handleReturn(
655656
$exitCode,

src/Command/AnalysisResult.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ final class AnalysisResult
2424
* @param list<string> $warnings
2525
* @param list<CollectedData> $collectedData
2626
* @param array<string, string> $changedProjectExtensionFilesOutsideOfAnalysedPaths
27+
* @param list<string> $processedFiles
2728
*/
2829
public function __construct(
2930
array $fileSpecificErrors,
@@ -37,6 +38,7 @@ public function __construct(
3738
private int $peakMemoryUsageBytes,
3839
private bool $isResultCacheUsed,
3940
private array $changedProjectExtensionFilesOutsideOfAnalysedPaths,
41+
private array $processedFiles = [],
4042
)
4143
{
4244
usort(
@@ -148,6 +150,14 @@ public function getChangedProjectExtensionFilesOutsideOfAnalysedPaths(): array
148150
return $this->changedProjectExtensionFilesOutsideOfAnalysedPaths;
149151
}
150152

153+
/**
154+
* @return list<string>
155+
*/
156+
public function getProcessedFiles(): array
157+
{
158+
return $this->processedFiles;
159+
}
160+
151161
/**
152162
* @api
153163
* @param list<Error> $fileSpecificErrors
@@ -166,6 +176,7 @@ public function withFileSpecificErrors(array $fileSpecificErrors): self
166176
$this->peakMemoryUsageBytes,
167177
$this->isResultCacheUsed,
168178
$this->changedProjectExtensionFilesOutsideOfAnalysedPaths,
179+
$this->processedFiles,
169180
);
170181
}
171182

tests/PHPStan/Command/AnalyseApplicationIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private function runPath(string $path, int $expectedStatusCode): string
7878
null,
7979
CommandHelper::DEFAULT_LEVEL,
8080
);
81-
[$analysisResult] = $analyserApplication->analyse(
81+
$analysisResult = $analyserApplication->analyse(
8282
[$path],
8383
true,
8484
$symfonyOutput,

0 commit comments

Comments
 (0)