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