1515namespace Humbug \PhpScoper \PhpParser \NodeVisitor \Collection ;
1616
1717use ArrayIterator ;
18+ use function count ;
19+ use Humbug \PhpScoper \PhpParser \Node \NamedIdentifier ;
1820use Humbug \PhpScoper \PhpParser \NodeVisitor \ParentNodeAppender ;
1921use IteratorAggregate ;
22+ use PhpParser \Node ;
2023use PhpParser \Node \Expr \ConstFetch ;
2124use PhpParser \Node \Expr \FuncCall ;
2225use PhpParser \Node \Name ;
2326use PhpParser \Node \Stmt \ClassLike ;
27+ use PhpParser \Node \Stmt \Function_ ;
2428use PhpParser \Node \Stmt \Use_ ;
2529use PhpParser \Node \Stmt \UseUse ;
2630use function Humbug \PhpScoper \clone_node ;
@@ -68,8 +72,8 @@ public function findStatementForNode(?Name $namespaceName, Name $node): ?Name
6872 $ parentNode = ParentNodeAppender::findParent ($ node );
6973
7074 if ($ parentNode instanceof ClassLike
71- && $ node-> hasAttribute ( ' original_node ' )
72- && $ node ->getAttribute ( ' original_node ' ) === $ parentNode ->name
75+ && $ node instanceof NamedIdentifier
76+ && $ node ->getOriginalNode ( ) === $ parentNode ->name
7377 ) {
7478 // The current node can either be the class like name or one of its elements, e.g. extends or implements.
7579 // In the first case, the node was original an Identifier.
@@ -86,7 +90,7 @@ public function findStatementForNode(?Name $namespaceName, Name $node): ?Name
8690 }
8791
8892 if ($ name === $ useStatement ->getAlias ()->toLowerString ()) {
89- if ($ parentNode instanceof FuncCall && 1 === count ($ node-> parts )) {
93+ if ($ this -> isFunctionName ($ node, $ parentNode )) {
9094 if (Use_::TYPE_FUNCTION === $ use_ ->type ) {
9195 return $ useStatement ->name ;
9296 }
@@ -122,4 +126,22 @@ public function getIterator(): iterable
122126 {
123127 return new ArrayIterator ($ this ->nodes );
124128 }
129+
130+ private function isFunctionName (Name $ node , ?Node $ parentNode ): bool
131+ {
132+ if (null === $ parentNode || 1 !== count ($ node ->parts )) {
133+ return false ;
134+ }
135+
136+ if ($ parentNode instanceof FuncCall) {
137+ return true ;
138+ }
139+
140+ if (false === ($ parentNode instanceof Function_)) {
141+ return false ;
142+ }
143+ /** @var Function_ $parentNode */
144+
145+ return $ node instanceof NamedIdentifier && $ node ->getOriginalNode () === $ parentNode ->name ;
146+ }
125147}
0 commit comments