Skip to content

Commit f595e35

Browse files
committed
PHPStan Pro - remove interactive fixer that never panned out
1 parent 199b249 commit f595e35

25 files changed

+26
-809
lines changed

conf/config.neon

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,6 @@ parametersSchema:
425425
usedLevel: string()
426426
cliAutoloadFile: schema(string(), nullable())
427427

428-
# internal - static reflection
429-
singleReflectionFile: schema(string(), nullable())
430-
singleReflectionInsteadOfFile: schema(string(), nullable())
431-
432428
rules:
433429
- PHPStan\Rules\Debug\DumpTypeRule
434430
- PHPStan\Rules\Debug\FileAssertRule
@@ -657,7 +653,6 @@ services:
657653
arguments:
658654
scanFileFinder: @fileFinderScan
659655
cacheFilePath: %resultCachePath%
660-
tempResultCachePath: %tempResultCachePath%
661656
analysedPaths: %analysedPaths%
662657
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
663658
usedLevel: %usedLevel%
@@ -671,7 +666,6 @@ services:
671666
class: PHPStan\Analyser\ResultCache\ResultCacheClearer
672667
arguments:
673668
cacheFilePath: %resultCachePath%
674-
tempResultCachePath: %tempResultCachePath%
675669

676670
-
677671
class: PHPStan\Cache\Cache
@@ -699,7 +693,6 @@ services:
699693
analysedPaths: %analysedPaths%
700694
currentWorkingDirectory: %currentWorkingDirectory%
701695
fixerTmpDir: %fixerTmpDir%
702-
maximumNumberOfProcesses: %parallel.maximumNumberOfProcesses%
703696

704697
-
705698
class: PHPStan\Dependency\DependencyResolver
@@ -738,8 +731,6 @@ services:
738731
usedLevel: %usedLevel%
739732
generateBaselineFile: %generateBaselineFile%
740733
cliAutoloadFile: %cliAutoloadFile%
741-
singleReflectionFile: %singleReflectionFile%
742-
singleReflectionInsteadOfFile: %singleReflectionInsteadOfFile%
743734

744735
-
745736
class: PHPStan\DependencyInjection\Reflection\ClassReflectionExtensionRegistryProvider
@@ -2016,7 +2007,6 @@ services:
20162007
analysedPaths: %analysedPaths%
20172008
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
20182009
analysedPathsFromConfig: %analysedPathsFromConfig%
2019-
singleReflectionFile: %singleReflectionFile%
20202010

20212011
-
20222012
implement: PHPStan\Reflection\BetterReflection\BetterReflectionProviderFactory
@@ -2059,7 +2049,6 @@ services:
20592049
currentPhpVersionRichParser: @currentPhpVersionRichParser
20602050
currentPhpVersionSimpleParser: @currentPhpVersionSimpleParser
20612051
php8Parser: @php8Parser
2062-
singleReflectionFile: %singleReflectionFile%
20632052
autowired: false
20642053

20652054
# Error formatters

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ parameters:
128128

129129
-
130130
message: "#^Call to an undefined method React\\\\Promise\\\\PromiseInterface\\:\\:done\\(\\)\\.$#"
131-
count: 2
131+
count: 1
132132
path: src/Command/FixerApplication.php
133133

134134
-

src/Analyser/ResultCache/ResultCacheClearer.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
namespace PHPStan\Analyser\ResultCache;
44

5-
use Symfony\Component\Finder\Finder;
65
use function dirname;
76
use function is_file;
87
use function unlink;
98

109
class ResultCacheClearer
1110
{
1211

13-
public function __construct(private string $cacheFilePath, private string $tempResultCachePath)
12+
public function __construct(private string $cacheFilePath)
1413
{
1514
}
1615

@@ -26,12 +25,4 @@ public function clear(): string
2625
return $dir;
2726
}
2827

29-
public function clearTemporaryCaches(): void
30-
{
31-
$finder = new Finder();
32-
foreach ($finder->files()->name('*.php')->in($this->tempResultCachePath) as $tmpResultCacheFile) {
33-
@unlink($tmpResultCacheFile->getPathname());
34-
}
35-
}
36-
3728
}

src/Analyser/ResultCache/ResultCacheManager.php

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,20 @@ class ResultCacheManager
5858
* @param string[] $bootstrapFiles
5959
* @param string[] $scanFiles
6060
* @param string[] $scanDirectories
61-
* @param array<string, string> $fileReplacements
6261
*/
6362
public function __construct(
6463
private ExportedNodeFetcher $exportedNodeFetcher,
6564
private FileFinder $scanFileFinder,
6665
private ReflectionProvider $reflectionProvider,
6766
private StubFilesProvider $stubFilesProvider,
6867
private string $cacheFilePath,
69-
private string $tempResultCachePath,
7068
private array $analysedPaths,
7169
private array $composerAutoloaderProjectPaths,
7270
private string $usedLevel,
7371
private ?string $cliAutoloadFile,
7472
private array $bootstrapFiles,
7573
private array $scanFiles,
7674
private array $scanDirectories,
77-
private array $fileReplacements,
7875
private bool $checkDependenciesOfProjectExtensionFiles,
7976
)
8077
{
@@ -84,7 +81,7 @@ public function __construct(
8481
* @param string[] $allAnalysedFiles
8582
* @param mixed[]|null $projectConfigArray
8683
*/
87-
public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?array $projectConfigArray, Output $output, ?string $resultCacheName = null): ResultCache
84+
public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?array $projectConfigArray, Output $output): ResultCache
8885
{
8986
if ($debug) {
9087
if ($output->isDebug()) {
@@ -100,13 +97,6 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?
10097
}
10198

10299
$cacheFilePath = $this->cacheFilePath;
103-
if ($resultCacheName !== null) {
104-
$tmpCacheFile = $this->tempResultCachePath . '/' . $resultCacheName . '.php';
105-
if (is_file($tmpCacheFile)) {
106-
$cacheFilePath = $tmpCacheFile;
107-
}
108-
}
109-
110100
if (!is_file($cacheFilePath)) {
111101
if ($output->isDebug()) {
112102
$output->writeLineFormatted('Result cache not used because the cache file does not exist.');
@@ -286,9 +276,6 @@ private function isMetaDifferent(array $cachedMeta, array $currentMeta): bool
286276
*/
287277
private function exportedNodesChanged(string $analysedFile, array $cachedFileExportedNodes): ?bool
288278
{
289-
if (array_key_exists($analysedFile, $this->fileReplacements)) {
290-
$analysedFile = $this->fileReplacements[$analysedFile];
291-
}
292279
$fileExportedNodes = $this->exportedNodeFetcher->fetchNodes($analysedFile);
293280

294281
$cachedSymbols = [];
@@ -336,7 +323,7 @@ public function process(AnalyserResult $analyserResult, ResultCache $resultCache
336323
}
337324

338325
$meta = $resultCache->getMeta();
339-
$doSave = function (array $errorsByFile, $collectedDataByFile, ?array $dependencies, array $exportedNodes, ?string $resultCacheName) use ($internalErrors, $resultCache, $output, $onlyFiles, $meta): bool {
326+
$doSave = function (array $errorsByFile, $collectedDataByFile, ?array $dependencies, array $exportedNodes) use ($internalErrors, $resultCache, $output, $onlyFiles, $meta): bool {
340327
if ($onlyFiles) {
341328
if ($output->isDebug()) {
342329
$output->writeLineFormatted('Result cache was not saved because only files were passed as analysed paths.');
@@ -371,7 +358,7 @@ public function process(AnalyserResult $analyserResult, ResultCache $resultCache
371358
}
372359
}
373360

374-
$this->save($resultCache->getLastFullAnalysisTime(), $resultCacheName, $errorsByFile, $collectedDataByFile, $dependencies, $exportedNodes, $meta);
361+
$this->save($resultCache->getLastFullAnalysisTime(), $errorsByFile, $collectedDataByFile, $dependencies, $exportedNodes, $meta);
375362

376363
if ($output->isDebug()) {
377364
$output->writeLineFormatted('Result cache is saved.');
@@ -383,7 +370,7 @@ public function process(AnalyserResult $analyserResult, ResultCache $resultCache
383370
if ($resultCache->isFullAnalysis()) {
384371
$saved = false;
385372
if ($save !== false) {
386-
$saved = $doSave($freshErrorsByFile, $freshCollectedDataByFile, $analyserResult->getDependencies(), $analyserResult->getExportedNodes(), is_string($save) ? $save : null);
373+
$saved = $doSave($freshErrorsByFile, $freshCollectedDataByFile, $analyserResult->getDependencies(), $analyserResult->getExportedNodes());
387374
} else {
388375
if ($output->isDebug()) {
389376
$output->writeLineFormatted('Result cache was not saved because it was not requested.');
@@ -400,7 +387,7 @@ public function process(AnalyserResult $analyserResult, ResultCache $resultCache
400387

401388
$saved = false;
402389
if ($save !== false) {
403-
$saved = $doSave($errorsByFile, $collectedDataByFile, $dependencies, $exportedNodes, is_string($save) ? $save : null);
390+
$saved = $doSave($errorsByFile, $collectedDataByFile, $dependencies, $exportedNodes);
404391
}
405392

406393
$flatErrors = [];
@@ -533,7 +520,6 @@ private function mergeExportedNodes(ResultCache $resultCache, array $freshExport
533520
*/
534521
private function save(
535522
int $lastFullAnalysisTime,
536-
?string $resultCacheName,
537523
array $errors,
538524
array $collectedData,
539525
array $dependencies,
@@ -597,10 +583,6 @@ private function save(
597583
ksort($exportedNodes);
598584

599585
$file = $this->cacheFilePath;
600-
if ($resultCacheName !== null) {
601-
$file = $this->tempResultCachePath . '/' . $resultCacheName . '.php';
602-
}
603-
604586
$projectConfigArray = $meta['projectConfig'];
605587
if ($projectConfigArray !== null) {
606588
$meta['projectConfig'] = Neon::encode($projectConfigArray);
@@ -765,9 +747,6 @@ private function getMeta(array $allAnalysedFiles, ?array $projectConfigArray): a
765747

766748
private function getFileHash(string $path): string
767749
{
768-
if (array_key_exists($path, $this->fileReplacements)) {
769-
$path = $this->fileReplacements[$path];
770-
}
771750
if (array_key_exists($path, $this->fileHashes)) {
772751
return $this->fileHashes[$path];
773752
}

src/Analyser/ResultCache/ResultCacheManagerFactory.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
interface ResultCacheManagerFactory
66
{
77

8-
/**
9-
* @param array<string, string> $fileReplacements
10-
*/
11-
public function create(array $fileReplacements): ResultCacheManager;
8+
public function create(): ResultCacheManager;
129

1310
}

src/Command/AnalyseApplication.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function analyse(
6363
InputInterface $input,
6464
): AnalysisResult
6565
{
66-
$resultCacheManager = $this->resultCacheManagerFactory->create([]);
66+
$resultCacheManager = $this->resultCacheManagerFactory->create();
6767

6868
$ignoredErrorHelperResult = $this->ignoredErrorHelper->initialize();
6969
if (count($ignoredErrorHelperResult->getErrors()) > 0) {
@@ -232,7 +232,7 @@ private function runAnalyser(
232232
}
233233
}
234234

235-
$analyserResult = $this->analyserRunner->runAnalyser($files, $allAnalysedFiles, $preFileCallback, $postFileCallback, $debug, true, $projectConfigFile, null, null, $input);
235+
$analyserResult = $this->analyserRunner->runAnalyser($files, $allAnalysedFiles, $preFileCallback, $postFileCallback, $debug, true, $projectConfigFile, $input);
236236

237237
if (!$debug) {
238238
$errorOutput->getStyle()->progressFinish();

src/Command/AnalyseCommand.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Command;
44

55
use OndraM\CiDetector\CiDetector;
6-
use PHPStan\Analyser\ResultCache\ResultCacheClearer;
76
use PHPStan\Command\ErrorFormatter\BaselineNeonErrorFormatter;
87
use PHPStan\Command\ErrorFormatter\ErrorFormatter;
98
use PHPStan\Command\ErrorFormatter\TableErrorFormatter;
@@ -365,7 +364,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
365364

366365
return $inceptionResult->handleReturn(1, $analysisResult->getPeakMemoryUsageBytes());
367366
}
368-
$container->getByType(ResultCacheClearer::class)->clearTemporaryCaches();
369367
$hasInternalErrors = $analysisResult->hasInternalErrors();
370368
$nonIgnorableErrorsByException = [];
371369
foreach ($analysisResult->getFileSpecificErrors() as $fileSpecificError) {

src/Command/AnalyserRunner.php

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use PHPStan\Parallel\Scheduler;
1010
use PHPStan\Process\CpuCoreCounter;
1111
use Symfony\Component\Console\Input\InputInterface;
12-
use function array_filter;
13-
use function array_values;
1412
use function count;
1513
use function function_exists;
1614
use function is_file;
@@ -42,8 +40,6 @@ public function runAnalyser(
4240
bool $debug,
4341
bool $allowParallel,
4442
?string $projectConfigFile,
45-
?string $tmpFile,
46-
?string $insteadOfFile,
4743
InputInterface $input,
4844
): AnalyserResult
4945
{
@@ -65,39 +61,16 @@ public function runAnalyser(
6561
&& $mainScript !== null
6662
&& $schedule->getNumberOfProcesses() > 0
6763
) {
68-
return $this->parallelAnalyser->analyse($schedule, $mainScript, $postFileCallback, $projectConfigFile, $tmpFile, $insteadOfFile, $input);
64+
return $this->parallelAnalyser->analyse($schedule, $mainScript, $postFileCallback, $projectConfigFile, $input);
6965
}
7066

7167
return $this->analyser->analyse(
72-
$this->switchTmpFile($files, $insteadOfFile, $tmpFile),
68+
$files,
7369
$preFileCallback,
7470
$postFileCallback,
7571
$debug,
76-
$this->switchTmpFile($allAnalysedFiles, $insteadOfFile, $tmpFile),
72+
$allAnalysedFiles,
7773
);
7874
}
7975

80-
/**
81-
* @param string[] $analysedFiles
82-
* @return string[]
83-
*/
84-
private function switchTmpFile(
85-
array $analysedFiles,
86-
?string $insteadOfFile,
87-
?string $tmpFile,
88-
): array
89-
{
90-
$analysedFiles = array_values(array_filter($analysedFiles, static function (string $file) use ($insteadOfFile): bool {
91-
if ($insteadOfFile === null) {
92-
return true;
93-
}
94-
return $file !== $insteadOfFile;
95-
}));
96-
if ($tmpFile !== null) {
97-
$analysedFiles[] = $tmpFile;
98-
}
99-
100-
return $analysedFiles;
101-
}
102-
10376
}

src/Command/CommandHelper.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ public static function begin(
8383
?string $level,
8484
bool $allowXdebug,
8585
bool $debugEnabled = false,
86-
?string $singleReflectionFile = null,
87-
?string $singleReflectionInsteadOfFile = null,
8886
bool $cleanupContainerCache = true,
8987
): InceptionResult
9088
{
@@ -286,7 +284,7 @@ public static function begin(
286284
}
287285

288286
try {
289-
$container = $containerFactory->create($tmpDir, $additionalConfigFiles, $paths, $composerAutoloaderProjectPaths, $analysedPathsFromConfig, $level ?? self::DEFAULT_LEVEL, $generateBaselineFile, $autoloadFile, $singleReflectionFile, $singleReflectionInsteadOfFile);
287+
$container = $containerFactory->create($tmpDir, $additionalConfigFiles, $paths, $composerAutoloaderProjectPaths, $analysedPathsFromConfig, $level ?? self::DEFAULT_LEVEL, $generateBaselineFile, $autoloadFile);
290288
} catch (InvalidConfigurationException | AssertionException $e) {
291289
$errorOutput->writeLineFormatted('<error>Invalid configuration:</error>');
292290
$errorOutput->writeLineFormatted($e->getMessage());

src/Command/DumpParametersCommand.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9292
unset($parameters['productionMode']);
9393
unset($parameters['tempDir']);
9494
unset($parameters['__validate']);
95-
// internal - static reflection
96-
unset($parameters['singleReflectionFile']);
97-
unset($parameters['singleReflectionInsteadOfFile']);
9895

9996
$output->writeln(Neon::encode($parameters, true));
10097

0 commit comments

Comments
 (0)