diff --git a/src/NodeVisitor/ParentClassNameCollectingNodeVisitor.php b/src/NodeVisitor/ParentClassNameCollectingNodeVisitor.php index 1948f83..1585950 100644 --- a/src/NodeVisitor/ParentClassNameCollectingNodeVisitor.php +++ b/src/NodeVisitor/ParentClassNameCollectingNodeVisitor.php @@ -40,10 +40,18 @@ public function getParentClassNames(): array sort($uniqueParentClassNames); // remove native classes - $namespacedClassNames = array_filter( - $uniqueParentClassNames, - fn (string $parentClassName): bool => str_contains($parentClassName, '\\') - ); + $namespacedClassNames = []; + foreach($uniqueParentClassNames as $className) { + try { + $reflection = new \ReflectionClass($className); + if ($reflection->isInternal()) { + continue; + } + $namespacedClassNames[] = $className; + } catch (\ReflectionException $e) { + $namespacedClassNames[] = $className; + } + } // remove obviously vendor names $namespacedClassNames = array_filter($namespacedClassNames, function (string $className): bool { diff --git a/tests/ParentClassResolver/Fixture/SomeClassWithRootNamespaceParent.php b/tests/ParentClassResolver/Fixture/SomeClassWithRootNamespaceParent.php new file mode 100644 index 0000000..31eeb61 --- /dev/null +++ b/tests/ParentClassResolver/Fixture/SomeClassWithRootNamespaceParent.php @@ -0,0 +1,9 @@ +parentClassResolver->resolve($phpFileInfos, function () { }); - $this->assertSame([SomeParentClass::class], $parentClassNames); + $this->assertSame([ + \SomeUnknownRootNamespaceClass::class, + SomeParentClass::class + ], $parentClassNames); } }