1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Jerowork\ClassDependenciesParser\PhpParser\NodeVisitor; |
6
|
|
|
|
7
|
|
|
use Jerowork\ClassDependenciesParser\ClassDependencies; |
8
|
|
|
use Jerowork\ClassDependenciesParser\PhpParser\NodeVisitor\InlineFqnParser\Decliner\InlineFqnDecliner; |
9
|
|
|
use Jerowork\ClassDependenciesParser\PhpParser\NodeVisitor\InlineFqnParser\Processor\InlineFqnProcessor; |
10
|
|
|
use PhpParser\Node; |
11
|
|
|
use PhpParser\Node\Name; |
12
|
|
|
use PhpParser\NodeVisitorAbstract; |
13
|
|
|
|
14
|
|
|
final class ParseInlineFqnNodeVisitor extends NodeVisitorAbstract |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param iterable<InlineFqnDecliner> $decliners |
18
|
|
|
* @param iterable<InlineFqnProcessor> $processors |
19
|
|
|
*/ |
20
|
4 |
|
public function __construct( |
21
|
|
|
private readonly ClassDependencies $classDependencies, |
22
|
|
|
private readonly iterable $decliners, |
23
|
|
|
private readonly iterable $processors, |
24
|
|
|
) { |
25
|
4 |
|
} |
26
|
|
|
|
27
|
4 |
|
public function enterNode(Node $node): int|Node|null |
28
|
|
|
{ |
29
|
4 |
|
if (!$node instanceof Name) { |
30
|
4 |
|
return parent::enterNode($node); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** @var Node $parent */ |
34
|
4 |
|
$parent = $node->getAttribute('parent'); |
35
|
|
|
|
36
|
4 |
|
foreach ($this->decliners as $decliner) { |
37
|
4 |
|
if ($decliner->shouldDecline($parent, $node, $this->classDependencies)) { |
38
|
4 |
|
return parent::enterNode($node); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
4 |
|
foreach ($this->processors as $processor) { |
43
|
4 |
|
if (!$processor->shouldProcess($parent, $node, $this->classDependencies)) { |
44
|
4 |
|
continue; |
45
|
|
|
} |
46
|
|
|
|
47
|
4 |
|
$fqn = $processor->process($parent, $node, $this->classDependencies); |
48
|
|
|
|
49
|
4 |
|
if ($fqn !== null) { |
50
|
4 |
|
$this->classDependencies->addInlineFqn($fqn); |
51
|
|
|
} |
52
|
|
|
|
53
|
4 |
|
break; |
54
|
|
|
} |
55
|
|
|
|
56
|
4 |
|
return parent::enterNode($node); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.