1: | <?php |
2: | |
3: | declare(strict_types=1); |
4: | |
5: | namespace PHPStan\BetterReflection\Util\Visitor; |
6: | |
7: | use PhpParser\Node; |
8: | use PhpParser\NodeTraverser; |
9: | use PhpParser\NodeVisitorAbstract; |
10: | |
11: | class ReturnNodeVisitor extends NodeVisitorAbstract |
12: | { |
13: | |
14: | private $returnNodes = []; |
15: | |
16: | public function enterNode(Node $node): ?int |
17: | { |
18: | if ($this->isScopeChangingNode($node)) { |
19: | return NodeTraverser::DONT_TRAVERSE_CHILDREN; |
20: | } |
21: | |
22: | if ($node instanceof Node\Stmt\Return_) { |
23: | $this->returnNodes[] = $node; |
24: | } |
25: | |
26: | return null; |
27: | } |
28: | |
29: | private function isScopeChangingNode(Node $node): bool |
30: | { |
31: | return $node instanceof Node\FunctionLike || $node instanceof Node\Stmt\Class_; |
32: | } |
33: | |
34: | |
35: | |
36: | |
37: | public function getReturnNodes(): array |
38: | { |
39: | return $this->returnNodes; |
40: | } |
41: | } |
42: | |