| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Analyser\Fiber; |
| 4: | |
| 5: | use Fiber; |
| 6: | use PhpParser\Node\Expr; |
| 7: | use PHPStan\Analyser\MutatingScope; |
| 8: | use PHPStan\Analyser\Scope; |
| 9: | use PHPStan\Type\Type; |
| 10: | |
| 11: | final class FiberScope extends MutatingScope |
| 12: | { |
| 13: | |
| 14: | public function toFiberScope(): self |
| 15: | { |
| 16: | return $this; |
| 17: | } |
| 18: | |
| 19: | public function toMutatingScope(): MutatingScope |
| 20: | { |
| 21: | return $this->scopeFactory->toMutatingFactory()->create( |
| 22: | $this->context, |
| 23: | $this->isDeclareStrictTypes(), |
| 24: | $this->getFunction(), |
| 25: | $this->getNamespace(), |
| 26: | $this->expressionTypes, |
| 27: | $this->nativeExpressionTypes, |
| 28: | $this->conditionalExpressions, |
| 29: | $this->inClosureBindScopeClasses, |
| 30: | $this->getAnonymousFunctionReflection(), |
| 31: | $this->isInFirstLevelStatement(), |
| 32: | $this->currentlyAssignedExpressions, |
| 33: | $this->currentlyAllowedUndefinedExpressions, |
| 34: | $this->inFunctionCallsStack, |
| 35: | $this->afterExtractCall, |
| 36: | $this->getParentScope(), |
| 37: | $this->nativeTypesPromoted, |
| 38: | ); |
| 39: | } |
| 40: | |
| 41: | |
| 42: | public function getType(Expr $node): Type |
| 43: | { |
| 44: | |
| 45: | $beforeScope = Fiber::suspend( |
| 46: | new BeforeScopeForExprRequest($node, $this), |
| 47: | ); |
| 48: | |
| 49: | return $beforeScope->toMutatingScope()->getType($node); |
| 50: | } |
| 51: | |
| 52: | public function getScopeType(Expr $expr): Type |
| 53: | { |
| 54: | return $this->toMutatingScope()->getType($expr); |
| 55: | } |
| 56: | |
| 57: | public function getScopeNativeType(Expr $expr): Type |
| 58: | { |
| 59: | return $this->toMutatingScope()->getNativeType($expr); |
| 60: | } |
| 61: | |
| 62: | |
| 63: | public function getNativeType(Expr $expr): Type |
| 64: | { |
| 65: | |
| 66: | $beforeScope = Fiber::suspend( |
| 67: | new BeforeScopeForExprRequest($expr, $this), |
| 68: | ); |
| 69: | |
| 70: | return $beforeScope->toMutatingScope()->getNativeType($expr); |
| 71: | } |
| 72: | |
| 73: | public function getKeepVoidType(Expr $node): Type |
| 74: | { |
| 75: | |
| 76: | $beforeScope = Fiber::suspend( |
| 77: | new BeforeScopeForExprRequest($node, $this), |
| 78: | ); |
| 79: | |
| 80: | return $beforeScope->toMutatingScope()->getKeepVoidType($node); |
| 81: | } |
| 82: | |
| 83: | } |
| 84: | |