1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace PHPStan\Analyser; |
4: | |
5: | use PhpParser\Node\Expr\Variable; |
6: | use PHPStan\Type\ArrayType; |
7: | use PHPStan\Type\MixedType; |
8: | use PHPStan\Type\StringType; |
9: | |
10: | |
11: | class ScopeFactory |
12: | { |
13: | |
14: | public function __construct( |
15: | private InternalScopeFactory $internalScopeFactory, |
16: | private bool $explicitMixedForGlobalVariables, |
17: | ) |
18: | { |
19: | } |
20: | |
21: | public function create(ScopeContext $context): MutatingScope |
22: | { |
23: | $superglobalType = new ArrayType(new StringType(), new MixedType($this->explicitMixedForGlobalVariables)); |
24: | $expressionTypes = [ |
25: | '$GLOBALS' => ExpressionTypeHolder::createYes(new Variable('GLOBALS'), $superglobalType), |
26: | '$_SERVER' => ExpressionTypeHolder::createYes(new Variable('_SERVER'), $superglobalType), |
27: | '$_GET' => ExpressionTypeHolder::createYes(new Variable('_GET'), $superglobalType), |
28: | '$_POST' => ExpressionTypeHolder::createYes(new Variable('_POST'), $superglobalType), |
29: | '$_FILES' => ExpressionTypeHolder::createYes(new Variable('_FILES'), $superglobalType), |
30: | '$_COOKIE' => ExpressionTypeHolder::createYes(new Variable('_COOKIE'), $superglobalType), |
31: | '$_SESSION' => ExpressionTypeHolder::createYes(new Variable('_SESSION'), $superglobalType), |
32: | '$_REQUEST' => ExpressionTypeHolder::createYes(new Variable('_REQUEST'), $superglobalType), |
33: | '$_ENV' => ExpressionTypeHolder::createYes(new Variable('_ENV'), $superglobalType), |
34: | ]; |
35: | |
36: | return $this->internalScopeFactory->create( |
37: | $context, |
38: | false, |
39: | null, |
40: | null, |
41: | $expressionTypes, |
42: | $expressionTypes, |
43: | ); |
44: | } |
45: | |
46: | } |
47: | |