@@ 30-80 (lines=51) @@ | ||
27 | * |
|
28 | * @private |
|
29 | */ |
|
30 | final class FunctionIdentifierRecorder extends NodeVisitorAbstract |
|
31 | { |
|
32 | private $prefix; |
|
33 | private $nameResolver; |
|
34 | private $whitelist; |
|
35 | ||
36 | public function __construct( |
|
37 | string $prefix, |
|
38 | FullyQualifiedNameResolver $nameResolver, |
|
39 | Whitelist $whitelist |
|
40 | ) { |
|
41 | $this->prefix = $prefix; |
|
42 | $this->nameResolver = $nameResolver; |
|
43 | $this->whitelist = $whitelist; |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * @inheritdoc |
|
48 | */ |
|
49 | public function enterNode(Node $node): Node |
|
50 | { |
|
51 | if (false === ($node instanceof Identifier) || false === ParentNodeAppender::hasParent($node)) { |
|
52 | return $node; |
|
53 | } |
|
54 | ||
55 | $parent = ParentNodeAppender::getParent($node); |
|
56 | ||
57 | if (false === ($parent instanceof Function_) || $node === $parent->returnType) { |
|
58 | return $node; |
|
59 | } |
|
60 | ||
61 | /** @var Identifier $node */ |
|
62 | $resolvedName = $this->nameResolver->resolveName($node)->getName(); |
|
63 | ||
64 | if (false === ($resolvedName instanceof FullyQualified)) { |
|
65 | return $node; |
|
66 | } |
|
67 | ||
68 | /** @var FullyQualified $resolvedName */ |
|
69 | if ($this->whitelist->isGlobalWhitelistedFunction((string) $resolvedName) |
|
70 | || $this->whitelist->isSymbolWhitelisted((string) $resolvedName) |
|
71 | ) { |
|
72 | $this->whitelist->recordWhitelistedFunction( |
|
73 | $resolvedName, |
|
74 | FullyQualified::concat($this->prefix, $resolvedName) |
|
75 | ); |
|
76 | } |
|
77 | ||
78 | return $node; |
|
79 | } |
|
80 | } |
|
81 |
@@ 31-86 (lines=56) @@ | ||
28 | * |
|
29 | * @private |
|
30 | */ |
|
31 | final class ClassIdentifierRecorder extends NodeVisitorAbstract |
|
32 | { |
|
33 | private $prefix; |
|
34 | private $nameResolver; |
|
35 | private $whitelist; |
|
36 | ||
37 | public function __construct( |
|
38 | string $prefix, |
|
39 | FullyQualifiedNameResolver $nameResolver, |
|
40 | Whitelist $whitelist |
|
41 | ) { |
|
42 | $this->prefix = $prefix; |
|
43 | $this->nameResolver = $nameResolver; |
|
44 | $this->whitelist = $whitelist; |
|
45 | } |
|
46 | ||
47 | /** |
|
48 | * @inheritdoc |
|
49 | */ |
|
50 | public function enterNode(Node $node): Node |
|
51 | { |
|
52 | if (false === ($node instanceof Identifier) || false === ParentNodeAppender::hasParent($node)) { |
|
53 | return $node; |
|
54 | } |
|
55 | ||
56 | $parent = ParentNodeAppender::getParent($node); |
|
57 | ||
58 | if (false === ($parent instanceof ClassLike) || $parent instanceof Trait_) { |
|
59 | return $node; |
|
60 | } |
|
61 | /** @var ClassLike $parent */ |
|
62 | if (null === $parent->name) { |
|
63 | return $node; |
|
64 | } |
|
65 | ||
66 | /** @var Identifier $node */ |
|
67 | $resolvedName = $this->nameResolver->resolveName($node)->getName(); |
|
68 | ||
69 | if (false === ($resolvedName instanceof FullyQualified)) { |
|
70 | return $node; |
|
71 | } |
|
72 | ||
73 | /** @var FullyQualified $resolvedName */ |
|
74 | if ($this->whitelist->isGlobalWhitelistedClass((string) $resolvedName) |
|
75 | || $this->whitelist->isSymbolWhitelisted((string) $resolvedName) |
|
76 | ) { |
|
77 | $this->whitelist->recordWhitelistedClass( |
|
78 | $resolvedName, |
|
79 | FullyQualified::concat($this->prefix, $resolvedName) |
|
80 | ); |
|
81 | } |
|
82 | ||
83 | return $node; |
|
84 | } |
|
85 | } |
|
86 |