1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Analyser;
4:
5: use PhpParser\Node;
6: use PhpParser\Node\Expr;
7: use PhpParser\Node\Name;
8: use PhpParser\Node\Param;
9: use PHPStan\Php\PhpVersions;
10: use PHPStan\Reflection\ClassConstantReflection;
11: use PHPStan\Reflection\ClassMemberAccessAnswerer;
12: use PHPStan\Reflection\ClassReflection;
13: use PHPStan\Reflection\ExtendedMethodReflection;
14: use PHPStan\Reflection\ExtendedParameterReflection;
15: use PHPStan\Reflection\ExtendedPropertyReflection;
16: use PHPStan\Reflection\FunctionReflection;
17: use PHPStan\Reflection\NamespaceAnswerer;
18: use PHPStan\Reflection\Php\PhpFunctionFromParserNodeReflection;
19: use PHPStan\TrinaryLogic;
20: use PHPStan\Type\ClosureType;
21: use PHPStan\Type\Type;
22: use PHPStan\Type\TypeWithClassName;
23:
24: /** @api */
25: interface Scope extends ClassMemberAccessAnswerer, NamespaceAnswerer
26: {
27:
28: public const SUPERGLOBAL_VARIABLES = [
29: 'GLOBALS',
30: '_SERVER',
31: '_GET',
32: '_POST',
33: '_FILES',
34: '_COOKIE',
35: '_SESSION',
36: '_REQUEST',
37: '_ENV',
38: ];
39:
40: public function getFile(): string;
41:
42: public function getFileDescription(): string;
43:
44: public function isDeclareStrictTypes(): bool;
45:
46: /**
47: * @phpstan-assert-if-true !null $this->getTraitReflection()
48: */
49: public function isInTrait(): bool;
50:
51: public function getTraitReflection(): ?ClassReflection;
52:
53: public function getFunction(): ?PhpFunctionFromParserNodeReflection;
54:
55: public function getFunctionName(): ?string;
56:
57: public function getParentScope(): ?self;
58:
59: public function hasVariableType(string $variableName): TrinaryLogic;
60:
61: public function getVariableType(string $variableName): Type;
62:
63: public function canAnyVariableExist(): bool;
64:
65: /**
66: * @return array<int, string>
67: */
68: public function getDefinedVariables(): array;
69:
70: /**
71: * @return array<int, string>
72: */
73: public function getMaybeDefinedVariables(): array;
74:
75: public function hasConstant(Name $name): bool;
76:
77: /** @deprecated Use getInstancePropertyReflection or getStaticPropertyReflection instead */
78: public function getPropertyReflection(Type $typeWithProperty, string $propertyName): ?ExtendedPropertyReflection;
79:
80: public function getInstancePropertyReflection(Type $typeWithProperty, string $propertyName): ?ExtendedPropertyReflection;
81:
82: public function getStaticPropertyReflection(Type $typeWithProperty, string $propertyName): ?ExtendedPropertyReflection;
83:
84: public function getMethodReflection(Type $typeWithMethod, string $methodName): ?ExtendedMethodReflection;
85:
86: public function getConstantReflection(Type $typeWithConstant, string $constantName): ?ClassConstantReflection;
87:
88: public function getConstantExplicitTypeFromConfig(string $constantName, Type $constantType): Type;
89:
90: public function getIterableKeyType(Type $iteratee): Type;
91:
92: public function getIterableValueType(Type $iteratee): Type;
93:
94: /**
95: * @phpstan-assert-if-true !null $this->getAnonymousFunctionReflection()
96: * @phpstan-assert-if-true !null $this->getAnonymousFunctionReturnType()
97: */
98: public function isInAnonymousFunction(): bool;
99:
100: public function getAnonymousFunctionReflection(): ?ClosureType;
101:
102: public function getAnonymousFunctionReturnType(): ?Type;
103:
104: public function getType(Expr $node): Type;
105:
106: public function getNativeType(Expr $expr): Type;
107:
108: public function getKeepVoidType(Expr $node): Type;
109:
110: /**
111: * The `getType()` method along with FNSR enabled
112: * waits for the Expr analysis to be completed
113: * in order to evaluate the type at the right place in the code.
114: *
115: * This prevents tricky bugs when reasoning about code like
116: * `doFoo($a = 1, $a)`.
117: *
118: * Sometimes this is counter-productive because we actually want
119: * to use the current Scope object contents to resolve the Expr type.
120: *
121: * In these cases use `getScopeType()`.
122: */
123: public function getScopeType(Expr $expr): Type;
124:
125: public function getScopeNativeType(Expr $expr): Type;
126:
127: public function resolveName(Name $name): string;
128:
129: public function resolveTypeByName(Name $name): TypeWithClassName;
130:
131: /**
132: * @param mixed $value
133: */
134: public function getTypeFromValue($value): Type;
135:
136: public function hasExpressionType(Expr $node): TrinaryLogic;
137:
138: public function isInClassExists(string $className): bool;
139:
140: public function isInFunctionExists(string $functionName): bool;
141:
142: public function isInClosureBind(): bool;
143:
144: /** @return list<FunctionReflection|ExtendedMethodReflection> */
145: public function getFunctionCallStack(): array;
146:
147: /** @return list<array{FunctionReflection|ExtendedMethodReflection, ExtendedParameterReflection|null}> */
148: public function getFunctionCallStackWithParameters(): array;
149:
150: public function isParameterValueNullable(Param $parameter): bool;
151:
152: /**
153: * @param Node\Name|Node\Identifier|Node\ComplexType|null $type
154: */
155: public function getFunctionType($type, bool $isNullable, bool $isVariadic): Type;
156:
157: public function isInExpressionAssign(Expr $expr): bool;
158:
159: public function isUndefinedExpressionAllowed(Expr $expr): bool;
160:
161: public function filterByTruthyValue(Expr $expr): self;
162:
163: public function filterByFalseyValue(Expr $expr): self;
164:
165: public function isInFirstLevelStatement(): bool;
166:
167: public function getPhpVersion(): PhpVersions;
168:
169: /** @internal */
170: public function toMutatingScope(): MutatingScope;
171:
172: }
173: