Skip to content

Commit 5c1a06f

Browse files
SanderMullerclaude
authored andcommitted
Fix cached results surviving a change of --autoload-file (#8034)
A different extra autoload changes what PHPStan can resolve, so cached results must not survive it. Repro: run without -a (helper functions unresolvable, files cached clean), then run with -a — the fresh inference suggestions stay hidden until --clear-cache. The configuration hash already includes the parameter bag, so registering the resolved autoload file path there at boot is enough. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c057924 commit 5c1a06f

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎bin/rector.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Rector\Bootstrap\RectorConfigsResolver;
77
use Rector\ChangesReporting\Output\JsonOutputFormatter;
88
use Rector\Configuration\Option;
9+
use Rector\Configuration\Parameter\SimpleParameterProvider;
910
use Rector\Console\Style\SymfonyStyleFactory;
1011
use Rector\DependencyInjection\LazyContainerFactory;
1112
use Rector\DependencyInjection\RectorContainerFactory;
@@ -127,6 +128,14 @@ public function loadIfExistsAndNotLoadedYet(string $filePath): void
127128
$autoloadIncluder->autoloadRectorInstalledAsGlobalDependency();
128129
$autoloadIncluder->autoloadFromCommandLine();
129130

131+
// a different extra autoload changes what PHPStan can resolve, so cached results
132+
// must not survive it: register it before the configuration hash is computed.
133+
// ArgvInput handles both "--autoload-file path" and "--autoload-file=path"
134+
$autoloadFileOption = (new ArgvInput())->getParameterOption(['--autoload-file', '-a'], null);
135+
if (is_string($autoloadFileOption) && $autoloadFileOption !== '') {
136+
SimpleParameterProvider::setParameter(Option::AUTOLOAD_FILE, realpath($autoloadFileOption) ?: $autoloadFileOption);
137+
}
138+
130139
$rectorConfigsResolver = new RectorConfigsResolver();
131140

132141
try {

0 commit comments

Comments
 (0)