Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Analyser/DirectInternalScopeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ final class DirectInternalScopeFactory implements InternalScopeFactory

private ExpressionResultStorageStack $expressionResultStorageStack;

/** The services the created scopes share, built on the first create(). */
private ?ScopeServices $services = null;

/**
* @param callable(Node $node, Scope $scope): void|null $nodeCallback
* @param ExtensionsCollection<ExpressionTypeResolverExtension> $expressionTypeResolverExtensions
Expand Down Expand Up @@ -75,9 +78,8 @@ public function create(
$className = NodeCallbackScope::class;
}

return new $className(
$this->services ??= new ScopeServices(
$this->container,
$this,
$this->reflectionProvider,
$this->initializerExprTypeResolver,
$this->expressionTypeResolverExtensions,
Expand All @@ -87,11 +89,16 @@ public function create(
$this->parser,
$this->constantResolver,
$this->expressionResultStorageStack,
$context,
$this->phpVersion,
$this->attributeReflectionFactory,
$this->configuredPhpVersionRangeHelper,
$this->nodeCallback,
);

return new $className(
$this->services,
$this,
$context,
$declareStrictTypes,
$function,
$namespace,
Expand Down
69 changes: 22 additions & 47 deletions src/Analyser/LazyInternalScopeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use PHPStan\Analyser\Generics\TemplateArgumentConstraints;
use PHPStan\Analyser\Generics\TemplateArgumentFrame;
use PHPStan\DependencyInjection\Container;
use PHPStan\DependencyInjection\ExtensionsCollection;
use PHPStan\DependencyInjection\GenerateFactory;
use PHPStan\Node\Printer\ExprPrinter;
use PHPStan\Parser\Parser;
Expand All @@ -29,28 +28,10 @@ final class LazyInternalScopeFactory implements InternalScopeFactory

private Parser $currentSimpleVersionParser;

private ?ReflectionProvider $reflectionProvider = null;

private ?InitializerExprTypeResolver $initializerExprTypeResolver = null;

/** @var ExtensionsCollection<ExpressionTypeResolverExtension>|null */
private ?ExtensionsCollection $expressionTypeResolverExtensions = null;

private ?ExprPrinter $exprPrinter = null;

private ?TypeSpecifier $typeSpecifier = null;

private ?PropertyReflectionFinder $propertyReflectionFinder = null;

private ?ConstantResolver $constantResolver = null;

private ExpressionResultStorageStack $expressionResultStorageStack;

private ?PhpVersion $phpVersionType = null;

private ?AttributeReflectionFactory $attributeReflectionFactory = null;

private ?ConfiguredPhpVersionRangeHelper $configuredPhpVersionRangeHelper = null;
/** The services the created scopes share, built on the first create(). */
private ?ScopeServices $services = null;

private ?self $twin = null;

Expand Down Expand Up @@ -97,36 +78,27 @@ public function create(
$className = NodeCallbackScope::class;
}

$this->reflectionProvider ??= $this->container->getByType(ReflectionProvider::class);
$this->initializerExprTypeResolver ??= $this->container->getByType(InitializerExprTypeResolver::class);
$this->expressionTypeResolverExtensions ??= $this->container->getExtensionsCollection(ExpressionTypeResolverExtension::class);
$this->exprPrinter ??= $this->container->getByType(ExprPrinter::class);
$this->typeSpecifier ??= $this->container->getByType(TypeSpecifier::class);
$this->propertyReflectionFinder ??= $this->container->getByType(PropertyReflectionFinder::class);

$this->constantResolver ??= $this->container->getByType(ConstantResolver::class);

$this->phpVersionType ??= $this->container->getByType(PhpVersion::class);
$this->attributeReflectionFactory ??= $this->container->getByType(AttributeReflectionFactory::class);
$this->configuredPhpVersionRangeHelper ??= $this->container->getByType(ConfiguredPhpVersionRangeHelper::class);

return new $className(
$this->services ??= new ScopeServices(
$this->container,
$this,
$this->reflectionProvider,
$this->initializerExprTypeResolver,
$this->expressionTypeResolverExtensions,
$this->exprPrinter,
$this->typeSpecifier,
$this->propertyReflectionFinder,
$this->container->getByType(ReflectionProvider::class),
$this->container->getByType(InitializerExprTypeResolver::class),
$this->container->getExtensionsCollection(ExpressionTypeResolverExtension::class),
$this->container->getByType(ExprPrinter::class),
$this->container->getByType(TypeSpecifier::class),
$this->container->getByType(PropertyReflectionFinder::class),
$this->currentSimpleVersionParser,
$this->constantResolver,
$this->container->getByType(ConstantResolver::class),
$this->expressionResultStorageStack,
$context,
$this->phpVersionType,
$this->attributeReflectionFactory,
$this->configuredPhpVersionRangeHelper,
$this->container->getByType(PhpVersion::class),
$this->container->getByType(AttributeReflectionFactory::class),
$this->container->getByType(ConfiguredPhpVersionRangeHelper::class),
$this->nodeCallback,
);

return new $className(
$this->services,
$this,
$context,
$declareStrictTypes,
$function,
$namespace,
Expand Down Expand Up @@ -184,6 +156,9 @@ private function twin(): self

$this->twin = new self($this->container, $this->nodeCallback, !$this->createsNodeCallbackScopes, $this->expressionResultStorageStack);
$this->twin->origin = WeakReference::create($this);
// the same services for both flavours: the same container, node
// callback and storage stack
$this->twin->services = $this->services;

return $this->twin;
}
Expand Down
Loading
Loading