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 getReturnStatements(): array
51: {
52: return $this->returnStatements;
53: }
54:
55: public function getReturnStatementsAfterFinally(): array
56: {
57: return $this->returnStatementsAfterFinally;
58: }
59:
60: public function getStatementResult(): StatementResult
61: {
62: return $this->statementResult;
63: }
64:
65: public function getExecutionEnds(): array
66: {
67: return $this->executionEnds;
68: }
69:
70: public function getImpurePoints(): array
71: {
72: return $this->impurePoints;
73: }
74:
75: public function returnsByRef(): bool
76: {
77: return $this->classMethod->byRef;
78: }
79:
80: public function hasNativeReturnTypehint(): bool
81: {
82: return $this->classMethod->returnType !== null;
83: }
84:
85: public function getMethodName(): string
86: {
87: return $this->classMethod->name->toString();
88: }
89:
90: public function getYieldStatements(): array
91: {
92: return $this->yieldStatements;
93: }
94:
95: public function getClassReflection(): ClassReflection
96: {
97: return $this->classReflection;
98: }
99:
100: public function getMethodReflection(): PhpMethodFromParserNodeReflection
101: {
102: return $this->methodReflection;
103: }
104:
105: /**
106: * @return Stmt[]
107: */
108: public function getStatements(): array
109: {
110: $stmts = $this->classMethod->getStmts();
111: if ($stmts === null) {
112: return [];
113: }
114:
115: return $stmts;
116: }
117:
118: public function isGenerator(): bool
119: {
120: return count($this->yieldStatements) > 0;
121: }
122:
123: #[Override]
124: public function getType(): string
125: {
126: return 'PHPStan_Node_MethodReturnStatementsNode';
127: }
128:
129: /**
130: * @return string[]
131: */
132: #[Override]
133: public function getSubNodeNames(): array
134: {
135: return [];
136: }
137:
138: }
139: