Skip to content

Commit e9f8dd7

Browse files
staabmondrejmirtes
authored andcommitted
LazyInternalScopeFactory: Prevent expensive repeated getService() calls
1 parent f0b3820 commit e9f8dd7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Analyser/LazyInternalScopeFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPStan\DependencyInjection\Type\DynamicReturnTypeExtensionRegistryProvider;
1010
use PHPStan\DependencyInjection\Type\ExpressionTypeResolverExtensionRegistryProvider;
1111
use PHPStan\Node\Printer\ExprPrinter;
12+
use PHPStan\Parser\Parser;
1213
use PHPStan\Php\PhpVersion;
1314
use PHPStan\Reflection\AttributeReflectionFactory;
1415
use PHPStan\Reflection\InitializerExprTypeResolver;
@@ -24,6 +25,8 @@ final class LazyInternalScopeFactory implements InternalScopeFactory
2425
/** @var int|array{min: int, max: int}|null */
2526
private int|array|null $phpVersion;
2627

28+
private Parser $currentSimpleVersionParser;
29+
2730
/**
2831
* @param callable(Node $node, Scope $scope): void|null $nodeCallback
2932
*/
@@ -34,6 +37,7 @@ public function __construct(
3437
)
3538
{
3639
$this->phpVersion = $this->container->getParameter('phpVersion');
40+
$this->currentSimpleVersionParser = $this->container->getService('currentPhpVersionSimpleParser');
3741
}
3842

3943
public function create(
@@ -69,7 +73,7 @@ public function create(
6973
$this->container->getByType(ExprPrinter::class),
7074
$this->container->getByType(TypeSpecifier::class),
7175
$this->container->getByType(PropertyReflectionFinder::class),
72-
$this->container->getService('currentPhpVersionSimpleParser'),
76+
$this->currentSimpleVersionParser,
7377
$this->container->getByType(NodeScopeResolver::class),
7478
$this->container->getByType(RicherScopeGetTypeHelper::class),
7579
$this->container->getByType(ConstantResolver::class),

0 commit comments

Comments
 (0)