| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Analyser; |
| 4: | |
| 5: | use PHPStan\Turbo\ShadowedByTurboExtension; |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | #[ShadowedByTurboExtension(implementation: __DIR__ . '/../../turbo-ext/src/StatementContext.cpp')] |
| 16: | final class StatementContext |
| 17: | { |
| 18: | |
| 19: | private function __construct( |
| 20: | private bool $isTopLevel, |
| 21: | private int $foreachUnrollFactor = 1, |
| 22: | private bool $resolveTemplateArguments = true, |
| 23: | ) |
| 24: | { |
| 25: | } |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | public static function createTopLevel(bool $resolveTemplateArguments = true): self |
| 31: | { |
| 32: | return new self(true, resolveTemplateArguments: $resolveTemplateArguments); |
| 33: | } |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | public static function createDeep(bool $resolveTemplateArguments = true): self |
| 39: | { |
| 40: | return new self(false, resolveTemplateArguments: $resolveTemplateArguments); |
| 41: | } |
| 42: | |
| 43: | public function isTopLevel(): bool |
| 44: | { |
| 45: | return $this->isTopLevel; |
| 46: | } |
| 47: | |
| 48: | public function getForeachUnrollFactor(): int |
| 49: | { |
| 50: | return $this->foreachUnrollFactor; |
| 51: | } |
| 52: | |
| 53: | public function shouldResolveTemplateArguments(): bool |
| 54: | { |
| 55: | return $this->resolveTemplateArguments; |
| 56: | } |
| 57: | |
| 58: | public function withoutTemplateArgumentResolution(): self |
| 59: | { |
| 60: | if (!$this->resolveTemplateArguments) { |
| 61: | return $this; |
| 62: | } |
| 63: | |
| 64: | return new self($this->isTopLevel, $this->foreachUnrollFactor, false); |
| 65: | } |
| 66: | |
| 67: | public function enterDeep(): self |
| 68: | { |
| 69: | if ($this->isTopLevel) { |
| 70: | return new self(false, $this->foreachUnrollFactor, $this->resolveTemplateArguments); |
| 71: | } |
| 72: | |
| 73: | return $this; |
| 74: | } |
| 75: | |
| 76: | public function enterUnrolledForeach(int $totalKeys): self |
| 77: | { |
| 78: | return new self($this->isTopLevel, $this->foreachUnrollFactor * $totalKeys, $this->resolveTemplateArguments); |
| 79: | } |
| 80: | |
| 81: | } |
| 82: | |