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 getReturnStatements(): array
46: {
47: return $this->returnStatements;
48: }
49:
50: public function getReturnStatementsAfterFinally(): array
51: {
52: return $this->returnStatementsAfterFinally;
53: }
54:
55: public function getStatementResult(): StatementResult
56: {
57: return $this->statementResult;
58: }
59:
60: public function getExecutionEnds(): array
61: {
62: return $this->executionEnds;
63: }
64:
65: public function getImpurePoints(): array
66: {
67: return $this->impurePoints;
68: }
69:
70: public function returnsByRef(): bool
71: {
72: return $this->function->byRef;
73: }
74:
75: public function hasNativeReturnTypehint(): bool
76: {
77: return $this->function->returnType !== null;
78: }
79:
80: public function getYieldStatements(): array
81: {
82: return $this->yieldStatements;
83: }
84:
85: public function isGenerator(): bool
86: {
87: return count($this->yieldStatements) > 0;
88: }
89:
90: #[Override]
91: public function getType(): string
92: {
93: return 'PHPStan_Node_FunctionReturnStatementsNode';
94: }
95:
96: /**
97: * @return string[]
98: */
99: #[Override]
100: public function getSubNodeNames(): array
101: {
102: return [];
103: }
104:
105: public function getFunctionReflection(): PhpFunctionFromParserNodeReflection
106: {
107: return $this->functionReflection;
108: }
109:
110: /**
111: * @return Stmt[]
112: */
113: public function getStatements(): array
114: {
115: return $this->function->getStmts();
116: }
117:
118: }
119: