/
LazyInternalScopeFactory.php
94 lines (85 loc) · 3.01 KB
/
LazyInternalScopeFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php declare(strict_types = 1);
namespace PHPStan\Analyser;
use PHPStan\DependencyInjection\Container;
use PHPStan\DependencyInjection\Type\DynamicReturnTypeExtensionRegistryProvider;
use PHPStan\Node\Printer\ExprPrinter;
use PHPStan\Php\PhpVersion;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\InitializerExprTypeResolver;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Properties\PropertyReflectionFinder;
use PHPStan\ShouldNotHappenException;
use function is_a;
class LazyInternalScopeFactory implements InternalScopeFactory
{
private bool $treatPhpDocTypesAsCertain;
private bool $explicitMixedInUnknownGenericNew;
/**
* @param class-string $scopeClass
*/
public function __construct(
private string $scopeClass,
private Container $container,
)
{
$this->treatPhpDocTypesAsCertain = $container->getParameter('treatPhpDocTypesAsCertain');
$this->explicitMixedInUnknownGenericNew = $this->container->getParameter('featureToggles')['explicitMixedInUnknownGenericNew'];
}
public function create(
ScopeContext $context,
bool $declareStrictTypes = false,
FunctionReflection|MethodReflection|null $function = null,
?string $namespace = null,
array $expressionTypes = [],
array $nativeExpressionTypes = [],
array $conditionalExpressions = [],
?string $inClosureBindScopeClass = null,
?ParametersAcceptor $anonymousFunctionReflection = null,
bool $inFirstLevelStatement = true,
array $currentlyAssignedExpressions = [],
array $currentlyAllowedUndefinedExpressions = [],
array $inFunctionCallsStack = [],
bool $afterExtractCall = false,
?Scope $parentScope = null,
bool $nativeTypesPromoted = false,
): MutatingScope
{
$scopeClass = $this->scopeClass;
if (!is_a($scopeClass, MutatingScope::class, true)) {
throw new ShouldNotHappenException();
}
return new $scopeClass(
$this,
$this->container->getByType(ReflectionProvider::class),
$this->container->getByType(InitializerExprTypeResolver::class),
$this->container->getByType(DynamicReturnTypeExtensionRegistryProvider::class)->getRegistry(),
$this->container->getByType(ExprPrinter::class),
$this->container->getByType(TypeSpecifier::class),
$this->container->getByType(PropertyReflectionFinder::class),
$this->container->getService('currentPhpVersionSimpleParser'),
$this->container->getByType(NodeScopeResolver::class),
$this->container->getByType(ConstantResolver::class),
$context,
$this->container->getByType(PhpVersion::class),
$declareStrictTypes,
$function,
$namespace,
$expressionTypes,
$nativeExpressionTypes,
$conditionalExpressions,
$inClosureBindScopeClass,
$anonymousFunctionReflection,
$inFirstLevelStatement,
$currentlyAssignedExpressions,
$currentlyAllowedUndefinedExpressions,
$inFunctionCallsStack,
$this->treatPhpDocTypesAsCertain,
$afterExtractCall,
$parentScope,
$nativeTypesPromoted,
$this->explicitMixedInUnknownGenericNew,
);
}
}