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