From 845927996c69dde0a44781226b28aca8729dc57b Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 27 Oct 2025 20:30:31 +0100 Subject: [PATCH] Reduce file-parsing in ResultCacheManager --- src/Analyser/ResultCache/ResultCacheManager.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Analyser/ResultCache/ResultCacheManager.php b/src/Analyser/ResultCache/ResultCacheManager.php index c687675f75..f3ef374a59 100644 --- a/src/Analyser/ResultCache/ResultCacheManager.php +++ b/src/Analyser/ResultCache/ResultCacheManager.php @@ -22,8 +22,9 @@ use PHPStan\Internal\ArrayHelper; use PHPStan\Internal\ComposerHelper; use PHPStan\PhpDoc\StubFilesProvider; -use PHPStan\Reflection\ReflectionProvider; use PHPStan\ShouldNotHappenException; +use ReflectionClass; +use ReflectionException; use Throwable; use function array_diff; use function array_fill_keys; @@ -82,7 +83,6 @@ public function __construct( private ExportedNodeFetcher $exportedNodeFetcher, #[AutowiredParameter(ref: '@fileFinderScan')] private FileFinder $scanFileFinder, - private ReflectionProvider $reflectionProvider, private StubFilesProvider $stubFilesProvider, private FileHelper $fileHelper, #[AutowiredParameter(ref: '%resultCachePath%')] @@ -936,13 +936,15 @@ private function getProjectExtensionFiles(?array $projectConfig, array $dependen $classes = ProjectConfigHelper::getServiceClassNames($projectConfig); foreach ($classes as $class) { - if (!$this->reflectionProvider->hasClass($class)) { + try { + // does not use static reflection to reduce file-parsing + $classReflection = new ReflectionClass($class); /** @phpstan-ignore argument.type */ + } catch (ReflectionException) { continue; } - $classReflection = $this->reflectionProvider->getClass($class); $fileName = $classReflection->getFileName(); - if ($fileName === null) { + if ($fileName === false) { continue; }