| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Analyser; |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | final class StatementContext |
| 14: | { |
| 15: | |
| 16: | private function __construct( |
| 17: | private bool $isTopLevel, |
| 18: | private int $foreachUnrollFactor = 1, |
| 19: | ) |
| 20: | { |
| 21: | } |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | public static function createTopLevel(): self |
| 27: | { |
| 28: | return new self(true); |
| 29: | } |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | public static function createDeep(): self |
| 35: | { |
| 36: | return new self(false); |
| 37: | } |
| 38: | |
| 39: | public function isTopLevel(): bool |
| 40: | { |
| 41: | return $this->isTopLevel; |
| 42: | } |
| 43: | |
| 44: | public function getForeachUnrollFactor(): int |
| 45: | { |
| 46: | return $this->foreachUnrollFactor; |
| 47: | } |
| 48: | |
| 49: | public function enterDeep(): self |
| 50: | { |
| 51: | if ($this->isTopLevel) { |
| 52: | return new self(false, $this->foreachUnrollFactor); |
| 53: | } |
| 54: | |
| 55: | return $this; |
| 56: | } |
| 57: | |
| 58: | public function enterUnrolledForeach(int $totalKeys): self |
| 59: | { |
| 60: | return new self($this->isTopLevel, $this->foreachUnrollFactor * $totalKeys); |
| 61: | } |
| 62: | |
| 63: | } |
| 64: | |