From 75a43ae08f7c702909bb2cfda2797b7f21875d26 Mon Sep 17 00:00:00 2001 From: Pavel Alexeev Date: Thu, 6 Jan 2022 01:03:30 +0300 Subject: [PATCH] #38 Try search parent class in the same namespace --- src/Parser/ClassParser.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Parser/ClassParser.php b/src/Parser/ClassParser.php index e23a069..9cec5c6 100644 --- a/src/Parser/ClassParser.php +++ b/src/Parser/ClassParser.php @@ -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) {