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: )
19: {
20: }
21:
22: /**
23: * @api
24: */
25: public static function createTopLevel(): self
26: {
27: return new self(true);
28: }
29:
30: /**
31: * @api
32: */
33: public static function createDeep(): self
34: {
35: return new self(false);
36: }
37:
38: public function isTopLevel(): bool
39: {
40: return $this->isTopLevel;
41: }
42:
43: public function enterDeep(): self
44: {
45: if ($this->isTopLevel) {
46: return self::createDeep();
47: }
48:
49: return $this;
50: }
51:
52: }
53: