Skip to content

Commit e231c40

Browse files
committed
Faster LazyInternalScopeFactory->create()
1 parent 479ff62 commit e231c40

File tree

1 file changed

+54
-13
lines changed

1 file changed

+54
-13
lines changed

src/Analyser/LazyInternalScopeFactory.php

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use PHPStan\Reflection\ReflectionProvider;
1818
use PHPStan\Rules\Properties\PropertyReflectionFinder;
1919
use PHPStan\Type\ClosureType;
20+
use PHPStan\Type\DynamicReturnTypeExtensionRegistry;
21+
use PHPStan\Type\ExpressionTypeResolverExtensionRegistry;
2022

2123
#[GenerateFactory(interface: InternalScopeFactoryFactory::class, resultType: LazyInternalScopeFactory::class)]
2224
final class LazyInternalScopeFactory implements InternalScopeFactory
@@ -25,7 +27,31 @@ final class LazyInternalScopeFactory implements InternalScopeFactory
2527
/** @var int|array{min: int, max: int}|null */
2628
private int|array|null $phpVersion;
2729

28-
private Parser $currentSimpleVersionParser;
30+
private readonly Parser $currentSimpleVersionParser;
31+
32+
private readonly ReflectionProvider $reflectionProvider;
33+
34+
private readonly InitializerExprTypeResolver $initializerExprTypeResolver;
35+
36+
private readonly DynamicReturnTypeExtensionRegistry $dynamicReturnTypeExtensionRegistry;
37+
38+
private readonly ExpressionTypeResolverExtensionRegistry $expressionTypeResolverExtensionRegistry;
39+
40+
private readonly ExprPrinter $exprPrinter;
41+
42+
private readonly TypeSpecifier $typeSpecifier;
43+
44+
private readonly PropertyReflectionFinder $propertyReflectionFinder;
45+
46+
private readonly NodeScopeResolver $nodeScopeResolver;
47+
48+
private readonly RicherScopeGetTypeHelper $richerScopeGetTypeHelper;
49+
50+
private readonly ConstantResolver $constantResolver;
51+
52+
private readonly PhpVersion $phpVersionType;
53+
54+
private readonly AttributeReflectionFactory $attributeReflectionFactory;
2955

3056
/**
3157
* @param callable(Node $node, Scope $scope): void|null $nodeCallback
@@ -38,6 +64,21 @@ public function __construct(
3864
{
3965
$this->phpVersion = $this->container->getParameter('phpVersion');
4066
$this->currentSimpleVersionParser = $this->container->getService('currentPhpVersionSimpleParser');
67+
68+
$this->reflectionProvider = $this->container->getByType(ReflectionProvider::class);
69+
$this->initializerExprTypeResolver = $this->container->getByType(InitializerExprTypeResolver::class);
70+
$this->dynamicReturnTypeExtensionRegistry = $this->container->getByType(DynamicReturnTypeExtensionRegistryProvider::class)->getRegistry();
71+
$this->expressionTypeResolverExtensionRegistry = $this->container->getByType(ExpressionTypeResolverExtensionRegistryProvider::class)->getRegistry();
72+
$this->exprPrinter = $this->container->getByType(ExprPrinter::class);
73+
$this->typeSpecifier = $this->container->getByType(TypeSpecifier::class);
74+
$this->propertyReflectionFinder = $this->container->getByType(PropertyReflectionFinder::class);
75+
76+
$this->nodeScopeResolver = $this->container->getByType(NodeScopeResolver::class);
77+
$this->richerScopeGetTypeHelper = $this->container->getByType(RicherScopeGetTypeHelper::class);
78+
$this->constantResolver = $this->container->getByType(ConstantResolver::class);
79+
80+
$this->phpVersionType = $this->container->getByType(PhpVersion::class);
81+
$this->attributeReflectionFactory = $this->container->getByType(AttributeReflectionFactory::class);
4182
}
4283

4384
public function create(
@@ -66,20 +107,20 @@ public function create(
66107

67108
return new $className(
68109
$this,
69-
$this->container->getByType(ReflectionProvider::class),
70-
$this->container->getByType(InitializerExprTypeResolver::class),
71-
$this->container->getByType(DynamicReturnTypeExtensionRegistryProvider::class)->getRegistry(),
72-
$this->container->getByType(ExpressionTypeResolverExtensionRegistryProvider::class)->getRegistry(),
73-
$this->container->getByType(ExprPrinter::class),
74-
$this->container->getByType(TypeSpecifier::class),
75-
$this->container->getByType(PropertyReflectionFinder::class),
110+
$this->reflectionProvider,
111+
$this->initializerExprTypeResolver,
112+
$this->dynamicReturnTypeExtensionRegistry,
113+
$this->expressionTypeResolverExtensionRegistry,
114+
$this->exprPrinter,
115+
$this->typeSpecifier,
116+
$this->propertyReflectionFinder,
76117
$this->currentSimpleVersionParser,
77-
$this->container->getByType(NodeScopeResolver::class),
78-
$this->container->getByType(RicherScopeGetTypeHelper::class),
79-
$this->container->getByType(ConstantResolver::class),
118+
$this->nodeScopeResolver,
119+
$this->richerScopeGetTypeHelper,
120+
$this->constantResolver,
80121
$context,
81-
$this->container->getByType(PhpVersion::class),
82-
$this->container->getByType(AttributeReflectionFactory::class),
122+
$this->phpVersionType,
123+
$this->attributeReflectionFactory,
83124
$this->phpVersion,
84125
$this->nodeCallback,
85126
$declareStrictTypes,

0 commit comments

Comments
 (0)