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