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\ClassMethod;
10: use PhpParser\NodeAbstract;
11: use PHPStan\Analyser\ImpurePoint;
12: use PHPStan\Analyser\StatementResult;
13: use PHPStan\Reflection\ClassReflection;
14: use PHPStan\Reflection\Php\PhpMethodFromParserNodeReflection;
15: use PHPStan\Turbo\ReferencedByTurboExtension;
16: use function count;
17:
18: /**
19: * @api
20: */
21: #[ReferencedByTurboExtension(key: 'methodReturnStatementsNode')]
22: final class MethodReturnStatementsNode extends NodeAbstract implements ReturnStatementsNode
23: {
24:
25: private ClassMethod $classMethod;
26:
27: /**
28: * @param list<ReturnStatement> $returnStatements
29: * @param list<ReturnStatement> $returnStatementsAfterFinally
30: * @param list<Yield_|YieldFrom> $yieldStatements
31: * @param list<ExecutionEndNode> $executionEnds
32: * @param ImpurePoint[] $impurePoints
33: */
34: public function __construct(
35: ClassMethod $method,
36: private array $returnStatements,
37: private array $returnStatementsAfterFinally,
38: private array $yieldStatements,
39: private StatementResult $statementResult,
40: private array $executionEnds,
41: private array $impurePoints,
42: private ClassReflection $classReflection,
43: private PhpMethodFromParserNodeReflection $methodReflection,
44: )
45: {
46: parent::__construct($method->getAttributes());
47: $this->classMethod = $method;
48: }
49:
50: public function getClassMethod(): ClassMethod
51: {
52: return $this->classMethod;
53: }
54:
55: public function getReturnStatements(): array
56: {
57: return $this->returnStatements;
58: }
59:
60: public function getReturnStatementsAfterFinally(): array
61: {
62: return $this->returnStatementsAfterFinally;
63: }
64:
65: public function getStatementResult(): StatementResult
66: {
67: return $this->statementResult;
68: }
69:
70: public function getExecutionEnds(): array
71: {
72: return $this->executionEnds;
73: }
74:
75: public function getImpurePoints(): array
76: {
77: return $this->impurePoints;
78: }
79:
80: public function returnsByRef(): bool
81: {
82: return $this->classMethod->byRef;
83: }
84:
85: public function hasNativeReturnTypehint(): bool
86: {
87: return $this->classMethod->returnType !== null;
88: }
89:
90: public function getMethodName(): string
91: {
92: return $this->classMethod->name->toString();
93: }
94:
95: public function getYieldStatements(): array
96: {
97: return $this->yieldStatements;
98: }
99:
100: public function getClassReflection(): ClassReflection
101: {
102: return $this->classReflection;
103: }
104:
105: public function getMethodReflection(): PhpMethodFromParserNodeReflection
106: {
107: return $this->methodReflection;
108: }
109:
110: /**
111: * @return Stmt[]
112: */
113: public function getStatements(): array
114: {
115: $stmts = $this->classMethod->getStmts();
116: if ($stmts === null) {
117: return [];
118: }
119:
120: return $stmts;
121: }
122:
123: public function isGenerator(): bool
124: {
125: return count($this->yieldStatements) > 0;
126: }
127:
128: #[Override]
129: public function getType(): string
130: {
131: return 'PHPStan_Node_MethodReturnStatementsNode';
132: }
133:
134: /**
135: * @return string[]
136: */
137: #[Override]
138: public function getSubNodeNames(): array
139: {
140: return [];
141: }
142:
143: }
144: