Repository navigation
Expand file tree
/
Copy pathMethodReturnStatementsNode.php
More file actions
154 lines (130 loc) · 3.24 KB
/
Copy pathMethodReturnStatementsNode.php
File metadata and controls
154 lines (130 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php declare(strict_types = 1);
namespace PHPStan\Node;
use Override;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\Expr\YieldFrom;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\NodeAbstract;
use PHPStan\Analyser\ImpurePoint;
use PHPStan\Analyser\StatementResult;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\Php\PhpMethodFromParserNodeReflection;
use PHPStan\Turbo\ReferencedByTurboExtension;
use function array_map;
use function count;
/**
* @api
*/
#[ReferencedByTurboExtension(key: 'methodReturnStatementsNode')]
final class MethodReturnStatementsNode extends NodeAbstract implements ReturnStatementsNode
{
private ClassMethod $classMethod;
/**
* @param list<ReturnStatement> $returnStatements
* @param list<ReturnStatement> $returnStatementsAfterFinally
* @param list<YieldStatement> $yieldStatements
* @param list<ExecutionEndNode> $executionEnds
* @param ImpurePoint[] $impurePoints
*/
public function __construct(
ClassMethod $method,
private array $returnStatements,
private array $returnStatementsAfterFinally,
private array $yieldStatements,
private StatementResult $statementResult,
private array $executionEnds,
private array $impurePoints,
private ClassReflection $classReflection,
private PhpMethodFromParserNodeReflection $methodReflection,
)
{
parent::__construct($method->getAttributes());
$this->classMethod = $method;
}
public function getClassMethod(): ClassMethod
{
return $this->classMethod;
}
public function getReturnStatements(): array
{
return $this->returnStatements;
}
public function getReturnStatementsAfterFinally(): array
{
return $this->returnStatementsAfterFinally;
}
public function getStatementResult(): StatementResult
{
return $this->statementResult;
}
public function getExecutionEnds(): array
{
return $this->executionEnds;
}
public function getImpurePoints(): array
{
return $this->impurePoints;
}
public function returnsByRef(): bool
{
return $this->classMethod->byRef;
}
public function hasNativeReturnTypehint(): bool
{
return $this->classMethod->returnType !== null;
}
public function getMethodName(): string
{
return $this->classMethod->name->toString();
}
public function getYieldStatements(): array
{
return array_map(static fn (YieldStatement $statement): Yield_|YieldFrom => $statement->getYieldNode(), $this->yieldStatements);
}
/**
* The yields with the scopes they are in.
*
* @return list<YieldStatement>
*/
public function getYieldStatementsWithScope(): array
{
return $this->yieldStatements;
}
public function getClassReflection(): ClassReflection
{
return $this->classReflection;
}
public function getMethodReflection(): PhpMethodFromParserNodeReflection
{
return $this->methodReflection;
}
/**
* @return Stmt[]
*/
public function getStatements(): array
{
$stmts = $this->classMethod->getStmts();
if ($stmts === null) {
return [];
}
return $stmts;
}
public function isGenerator(): bool
{
return count($this->yieldStatements) > 0;
}
#[Override]
public function getType(): string
{
return 'PHPStan_Node_MethodReturnStatementsNode';
}
/**
* @return string[]
*/
#[Override]
public function getSubNodeNames(): array
{
return [];
}
}