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\ClassMethod;
9: use PhpParser\NodeAbstract;
10: use PHPStan\Analyser\ImpurePoint;
11: use PHPStan\Analyser\StatementResult;
12: use PHPStan\Reflection\ClassReflection;
13: use PHPStan\Reflection\ExtendedMethodReflection;
14: use function count;
15:
16: /**
17: * @api
18: * @final
19: */
20: 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 ExtendedMethodReflection $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(): ExtendedMethodReflection
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: public function getType(): string
115: {
116: return 'PHPStan_Node_MethodReturnStatementsNode';
117: }
118:
119: /**
120: * @return string[]
121: */
122: public function getSubNodeNames(): array
123: {
124: return [];
125: }
126:
127: }
128: