diff --git a/src/Analyser/LazyInternalScopeFactory.php b/src/Analyser/LazyInternalScopeFactory.php index 611c11f5987..21bfb115394 100644 --- a/src/Analyser/LazyInternalScopeFactory.php +++ b/src/Analyser/LazyInternalScopeFactory.php @@ -17,6 +17,8 @@ use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\Properties\PropertyReflectionFinder; use PHPStan\Type\ClosureType; +use PHPStan\Type\DynamicReturnTypeExtensionRegistry; +use PHPStan\Type\ExpressionTypeResolverExtensionRegistry; #[GenerateFactory(interface: InternalScopeFactoryFactory::class, resultType: LazyInternalScopeFactory::class)] final class LazyInternalScopeFactory implements InternalScopeFactory @@ -27,6 +29,30 @@ final class LazyInternalScopeFactory implements InternalScopeFactory private Parser $currentSimpleVersionParser; + private ?ReflectionProvider $reflectionProvider = null; + + private ?InitializerExprTypeResolver $initializerExprTypeResolver = null; + + private ?DynamicReturnTypeExtensionRegistry $dynamicReturnTypeExtensionRegistry = null; + + private ?ExpressionTypeResolverExtensionRegistry $expressionTypeResolverExtensionRegistry = null; + + private ?ExprPrinter $exprPrinter = null; + + private ?TypeSpecifier $typeSpecifier = null; + + private ?PropertyReflectionFinder $propertyReflectionFinder = null; + + private ?NodeScopeResolver $nodeScopeResolver = null; + + private ?RicherScopeGetTypeHelper $richerScopeGetTypeHelper = null; + + private ?ConstantResolver $constantResolver = null; + + private ?PhpVersion $phpVersionType = null; + + private ?AttributeReflectionFactory $attributeReflectionFactory = null; + /** * @param callable(Node $node, Scope $scope): void|null $nodeCallback */ @@ -64,22 +90,37 @@ public function create( $className = FiberScope::class; } + $this->reflectionProvider ??= $this->container->getByType(ReflectionProvider::class); + $this->initializerExprTypeResolver ??= $this->container->getByType(InitializerExprTypeResolver::class); + $this->dynamicReturnTypeExtensionRegistry ??= $this->container->getByType(DynamicReturnTypeExtensionRegistryProvider::class)->getRegistry(); + $this->expressionTypeResolverExtensionRegistry ??= $this->container->getByType(ExpressionTypeResolverExtensionRegistryProvider::class)->getRegistry(); + $this->exprPrinter ??= $this->container->getByType(ExprPrinter::class); + $this->typeSpecifier ??= $this->container->getByType(TypeSpecifier::class); + $this->propertyReflectionFinder ??= $this->container->getByType(PropertyReflectionFinder::class); + + $this->nodeScopeResolver ??= $this->container->getByType(NodeScopeResolver::class); + $this->richerScopeGetTypeHelper ??= $this->container->getByType(RicherScopeGetTypeHelper::class); + $this->constantResolver ??= $this->container->getByType(ConstantResolver::class); + + $this->phpVersionType ??= $this->container->getByType(PhpVersion::class); + $this->attributeReflectionFactory ??= $this->container->getByType(AttributeReflectionFactory::class); + return new $className( $this, - $this->container->getByType(ReflectionProvider::class), - $this->container->getByType(InitializerExprTypeResolver::class), - $this->container->getByType(DynamicReturnTypeExtensionRegistryProvider::class)->getRegistry(), - $this->container->getByType(ExpressionTypeResolverExtensionRegistryProvider::class)->getRegistry(), - $this->container->getByType(ExprPrinter::class), - $this->container->getByType(TypeSpecifier::class), - $this->container->getByType(PropertyReflectionFinder::class), + $this->reflectionProvider, + $this->initializerExprTypeResolver, + $this->dynamicReturnTypeExtensionRegistry, + $this->expressionTypeResolverExtensionRegistry, + $this->exprPrinter, + $this->typeSpecifier, + $this->propertyReflectionFinder, $this->currentSimpleVersionParser, - $this->container->getByType(NodeScopeResolver::class), - $this->container->getByType(RicherScopeGetTypeHelper::class), - $this->container->getByType(ConstantResolver::class), + $this->nodeScopeResolver, + $this->richerScopeGetTypeHelper, + $this->constantResolver, $context, - $this->container->getByType(PhpVersion::class), - $this->container->getByType(AttributeReflectionFactory::class), + $this->phpVersionType, + $this->attributeReflectionFactory, $this->phpVersion, $this->nodeCallback, $declareStrictTypes,