Repository navigation
Expand file tree
/
Copy pathFunctionReturnStatementsNode.php
More file actions
134 lines (114 loc) · 2.86 KB
/
Copy pathFunctionReturnStatementsNode.php
File metadata and controls
134 lines (114 loc) · 2.86 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
<?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\Function_;
use PhpParser\NodeAbstract;
use PHPStan\Analyser\ImpurePoint;
use PHPStan\Analyser\StatementResult;
use PHPStan\Reflection\Php\PhpFunctionFromParserNodeReflection;
use PHPStan\Turbo\ReferencedByTurboExtension;
use function array_map;
use function count;
/**
* @api
*/
#[ReferencedByTurboExtension(key: 'functionReturnStatementsNode')]
final class FunctionReturnStatementsNode extends NodeAbstract implements ReturnStatementsNode
{
/**
* @param list<ReturnStatement> $returnStatements
* @param list<ReturnStatement> $returnStatementsAfterFinally
* @param list<YieldStatement> $yieldStatements
* @param list<ExecutionEndNode> $executionEnds
* @param ImpurePoint[] $impurePoints
*/
public function __construct(
private Function_ $function,
private array $returnStatements,
private array $returnStatementsAfterFinally,
private array $yieldStatements,
private StatementResult $statementResult,
private array $executionEnds,
private array $impurePoints,
private PhpFunctionFromParserNodeReflection $functionReflection,
)
{
parent::__construct($function->getAttributes());
}
public function getFunction(): Function_
{
return $this->function;
}
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->function->byRef;
}
public function hasNativeReturnTypehint(): bool
{
return $this->function->returnType !== null;
}
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 isGenerator(): bool
{
return count($this->yieldStatements) > 0;
}
#[Override]
public function getType(): string
{
return 'PHPStan_Node_FunctionReturnStatementsNode';
}
/**
* @return string[]
*/
#[Override]
public function getSubNodeNames(): array
{
return [];
}
public function getFunctionReflection(): PhpFunctionFromParserNodeReflection
{
return $this->functionReflection;
}
/**
* @return Stmt[]
*/
public function getStatements(): array
{
return $this->function->getStmts();
}
}