1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Analyser;
4:
5: /**
6: * Object of this class is one of the parameters of `NodeScopeResolver::processStmtNodes()`.
7: *
8: * It determines whether loops will be analysed once or multiple times
9: * until the types "stabilize".
10: *
11: * When in doubt, use `StatementContext::createTopLevel()`.
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: * @api
25: */
26: public static function createTopLevel(): self
27: {
28: return new self(true);
29: }
30:
31: /**
32: * @api
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: