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 array_map;
16: use function count;
17:
18: /**
19: * @api
20: */
21: #[ReferencedByTurboExtension(key: 'functionReturnStatementsNode')]
22: final class FunctionReturnStatementsNode extends NodeAbstract implements ReturnStatementsNode
23: {
24:
25: /**
26: * @param list<ReturnStatement> $returnStatements
27: * @param list<ReturnStatement> $returnStatementsAfterFinally
28: * @param list<YieldStatement> $yieldStatements
29: * @param list<ExecutionEndNode> $executionEnds
30: * @param ImpurePoint[] $impurePoints
31: */
32: public function __construct(
33: private Function_ $function,
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: private PhpFunctionFromParserNodeReflection $functionReflection,
41: )
42: {
43: parent::__construct($function->getAttributes());
44: }
45:
46: public function getFunction(): Function_
47: {
48: return $this->function;
49: }
50:
51: public function getReturnStatements(): array
52: {
53: return $this->returnStatements;
54: }
55:
56: public function getReturnStatementsAfterFinally(): array
57: {
58: return $this->returnStatementsAfterFinally;
59: }
60:
61: public function getStatementResult(): StatementResult
62: {
63: return $this->statementResult;
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 returnsByRef(): bool
77: {
78: return $this->function->byRef;
79: }
80:
81: public function hasNativeReturnTypehint(): bool
82: {
83: return $this->function->returnType !== null;
84: }
85:
86: public function getYieldStatements(): array
87: {
88: return array_map(static fn (YieldStatement $statement): Yield_|YieldFrom => $statement->getYieldNode(), $this->yieldStatements);
89: }
90:
91: /**
92: * The yields with the scopes they are in.
93: *
94: * @return list<YieldStatement>
95: */
96: public function getYieldStatementsWithScope(): array
97: {
98: return $this->yieldStatements;
99: }
100:
101: public function isGenerator(): bool
102: {
103: return count($this->yieldStatements) > 0;
104: }
105:
106: #[Override]
107: public function getType(): string
108: {
109: return 'PHPStan_Node_FunctionReturnStatementsNode';
110: }
111:
112: /**
113: * @return string[]
114: */
115: #[Override]
116: public function getSubNodeNames(): array
117: {
118: return [];
119: }
120:
121: public function getFunctionReflection(): PhpFunctionFromParserNodeReflection
122: {
123: return $this->functionReflection;
124: }
125:
126: /**
127: * @return Stmt[]
128: */
129: public function getStatements(): array
130: {
131: return $this->function->getStmts();
132: }
133:
134: }
135: