diff --git a/src/Parser/ClassParser.php b/src/Parser/ClassParser.php index e23a069..0864d76 100644 --- a/src/Parser/ClassParser.php +++ b/src/Parser/ClassParser.php @@ -104,7 +104,7 @@ public function getUsedClasses(): array if ($nStatement instanceof Use_) { /** @var UseUse $use */ foreach ($nStatement->uses as $use) { - $className = $use->name->parts[array_key_last($use->name->parts)]; + $className = $use->alias ? $use->alias->name : $use->name->parts[array_key_last($use->name->parts)]; $usedClasses[$className] = implode('\\', $use->name->parts); } } @@ -190,11 +190,21 @@ private function getParentClassStatements(): ?array return []; } - if (null !== $usedClasses[$this->getParentClassName()]) { + if (null !== @$usedClasses[$this->getParentClassName()]) { $parentClass = $usedClasses[$this->getParentClassName()]; } - $rc = new ReflectionClass($parentClass); + try { + $rc = new ReflectionClass($parentClass); + } + catch (\ReflectionException $e) { + try { + $rc = new ReflectionClass($this->getNamespace() . '\\' . $parentClass); + } + catch (\ReflectionException $e) { + throw new ReflectionException("Parent class [{$parentClass}] for [{$this->getNamespace()}\\{$this->getClassName()}] not found!", $e->getCode(), $e); + } + } $filename = $rc->getFileName(); if (false === $filename) {