Skip to content

Commit

Permalink
php-kafka#38, php-kafka#40 Use reflection for robust resolving parent…
Browse files Browse the repository at this point in the history
… class
  • Loading branch information
Pavel Alexeev authored and Pavel Alexeev committed Jan 5, 2022
1 parent 75a43ae commit 2b0a85e
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/Parser/ClassParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,28 +184,18 @@ private function getParentClassStatements(): ?array
{
/** @var class-string[] $usedClasses */
$usedClasses = $this->getUsedClasses();
$parentClass = $this->getParentClassName();

if (null === $parentClass) {
return [];
}

if (null !== @$usedClasses[$this->getParentClassName()]) {
$parentClass = $usedClasses[$this->getParentClassName()];
}

try {
$rc = new ReflectionClass($parentClass);
$pc = (new ReflectionClass($this->getNamespace() . '\\' . $this->getClassName()))->getParentClass();
}
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);
}
throw new ReflectionException("Can't get parent class for [{$this->getNamespace()}\\{$this->getClassName()}]!", $e->getCode(), $e);
}
$filename = $rc->getFileName();
if (false === $pc) {
return [];
}

$filename = $pc->getFileName();

if (false === $filename) {
return [];
Expand Down

0 comments on commit 2b0a85e

Please sign in to comment.