1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Node;
4:
5: use Override;
6: use PhpParser\Node;
7: use PhpParser\Node\Expr\Closure;
8: use PhpParser\Node\Expr\Yield_;
9: use PhpParser\Node\Expr\YieldFrom;
10: use PhpParser\NodeAbstract;
11: use PHPStan\Analyser\ImpurePoint;
12: use PHPStan\Analyser\StatementResult;
13: use PHPStan\Turbo\ReferencedByTurboExtension;
14: use function count;
15:
16: /**
17: * @api
18: */
19: #[ReferencedByTurboExtension(key: 'closureReturnStatementsNode')]
20: final class ClosureReturnStatementsNode extends NodeAbstract implements ReturnStatementsNode
21: {
22:
23: private Node\Expr\Closure $closureExpr;
24:
25: /**
26: * @param list<ReturnStatement> $returnStatements
27: * @param list<ReturnStatement> $returnStatementsAfterFinally
28: * @param list<Yield_|YieldFrom> $yieldStatements
29: * @param list<ExecutionEndNode> $executionEnds
30: * @param ImpurePoint[] $impurePoints
31: */
32: public function __construct(
33: Closure $closureExpr,
34: private array $returnStatements,
35: private array $returnStatementsAfterFinally,
36: private array $yieldStatements,
37: private StatementResult $statementResult,
38: private array $executionEnds,
39: private array $impurePoints,
40: )
41: {
42: parent::__construct($closureExpr->getAttributes());
43: $this->closureExpr = $closureExpr;
44: }
45:
46: public function getClosureExpr(): Closure
47: {
48: return $this->closureExpr;
49: }
50:
51: public function hasNativeReturnTypehint(): bool
52: {
53: return $this->closureExpr->returnType !== null;
54: }
55:
56: public function getReturnStatements(): array
57: {
58: return $this->returnStatements;
59: }
60:
61: public function getReturnStatementsAfterFinally(): array
62: {
63: return $this->returnStatementsAfterFinally;
64: }
65:
66: public function getExecutionEnds(): array
67: {
68: return $this->executionEnds;
69: }
70:
71: public function getImpurePoints(): array
72: {
73: return $this->impurePoints;
74: }
75:
76: public function getYieldStatements(): array
77: {
78: return $this->yieldStatements;
79: }
80:
81: public function isGenerator(): bool
82: {
83: return count($this->yieldStatements) > 0;
84: }
85:
86: public function getStatementResult(): StatementResult
87: {
88: return $this->statementResult;
89: }
90:
91: public function returnsByRef(): bool
92: {
93: return $this->closureExpr->byRef;
94: }
95:
96: #[Override]
97: public function getType(): string
98: {
99: return 'PHPStan_Node_ClosureReturnStatementsNode';
100: }
101:
102: /**
103: * @return string[]
104: */
105: #[Override]
106: public function getSubNodeNames(): array
107: {
108: return [];
109: }
110:
111: }
112: