forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeScanner.php
More file actions
47 lines (36 loc) · 1.01 KB
/
Copy pathNodeScanner.php
File metadata and controls
47 lines (36 loc) · 1.01 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
<?php declare(strict_types = 1);
namespace PHPStan\Node;
use PhpParser\Node;
use PHPStan\Turbo\ShadowedByTurboExtension;
use function is_array;
/**
* Recursive AST queries over php-parser node graphs.
*/
#[ShadowedByTurboExtension(turboClass: 'PHPStanTurbo\NodeScanner', implementation: __DIR__ . '/../../turbo-ext/src/NodeScanner.cpp')]
final class NodeScanner
{
public static function nodeIsOrContainsYield(Node $node): bool
{
if ($node instanceof Node\Expr\Yield_) {
return true;
}
if ($node instanceof Node\Expr\YieldFrom) {
return true;
}
foreach ($node->getSubNodeNames() as $nodeName) {
$nodeProperty = $node->$nodeName;
if ($nodeProperty instanceof Node && self::nodeIsOrContainsYield($nodeProperty)) {
return true;
}
if (!is_array($nodeProperty)) {
continue;
}
foreach ($nodeProperty as $nodePropertyArrayItem) {
if ($nodePropertyArrayItem instanceof Node && self::nodeIsOrContainsYield($nodePropertyArrayItem)) {
return true;
}
}
}
return false;
}
}