File tree Expand file tree Collapse file tree 3 files changed +29
-16
lines changed
CodingStyle/ClassNameImport
tests/Issues/AutoImport/Fixture Expand file tree Collapse file tree 3 files changed +29
-16
lines changed Original file line number Diff line number Diff line change 1010use PhpParser \Node \Stmt \Namespace_ ;
1111use PhpParser \Node \Stmt \Use_ ;
1212use PhpParser \Node \Stmt \UseUse ;
13+ use Rector \PhpParser \Node \CustomNode \FileWithoutNamespace ;
1314
1415final readonly class AliasUsesResolver
1516{
@@ -24,9 +25,12 @@ public function __construct(
2425 */
2526 public function resolveFromNode (Node $ node , array $ stmts ): array
2627 {
27- if (! $ node instanceof Namespace_) {
28- /** @var Namespace_[] $namespaces */
29- $ namespaces = array_filter ($ stmts , static fn (Stmt $ stmt ): bool => $ stmt instanceof Namespace_);
28+ if (! $ node instanceof Namespace_ && ! $ node instanceof FileWithoutNamespace) {
29+ /** @var Namespace_[]|FileWithoutNamespace[] $namespaces */
30+ $ namespaces = array_filter (
31+ $ stmts ,
32+ static fn (Stmt $ stmt ): bool => $ stmt instanceof Namespace_ || $ stmt instanceof FileWithoutNamespace
33+ );
3034 if (count ($ namespaces ) !== 1 ) {
3135 return [];
3236 }
Original file line number Diff line number Diff line change @@ -71,23 +71,17 @@ private function resolveNamespace(): Namespace_|FileWithoutNamespace|null
7171 return null ;
7272 }
7373
74- $ namespaces = array_filter ($ newStmts , static fn (Stmt $ stmt ): bool => $ stmt instanceof Namespace_);
74+ /** @var Namespace_[]|FileWithoutNamespace[] $namespaces */
75+ $ namespaces = array_filter (
76+ $ newStmts ,
77+ static fn (Stmt $ stmt ): bool => $ stmt instanceof Namespace_ || $ stmt instanceof FileWithoutNamespace
78+ );
7579
7680 // multiple namespaces is not supported
77- if (count ($ namespaces ) > 1 ) {
78- return null ;
79- }
80-
81- $ currentNamespace = current ($ namespaces );
82- if ($ currentNamespace instanceof Namespace_) {
83- return $ currentNamespace ;
84- }
85-
86- $ currentStmt = current ($ newStmts );
87- if (! $ currentStmt instanceof FileWithoutNamespace) {
81+ if (count ($ namespaces ) !== 1 ) {
8882 return null ;
8983 }
9084
91- return $ currentStmt ;
85+ return current ( $ namespaces ) ;
9286 }
9387}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Some \Class_ as ClassOrig ;
4+ use PhpParser \Node ;
5+
6+ final class SkipConflictLastNameAliasedUsed
7+ {
8+ /**
9+ * @param Node\Stmt\Class_ $param
10+ */
11+ public function run ($ param ): void
12+ {
13+ new ClassOrig ();
14+ }
15+ }
You can’t perform that action at this time.
0 commit comments