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