Skip to content

Commit

Permalink
Microoptimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 2, 2021
1 parent 626f72a commit 1463c57
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -984,37 +984,38 @@ public function getClassReflection(): ?ClassReflection
*/
public function getAncestorWithClassName(string $className): ?TypeWithClassName
{
$broker = Broker::getInstance();
if (!$broker->hasClass($className)) {
return null;
}
$theirReflection = $broker->getClass($className);
$description = $this->describeCache();
if (isset(self::$ancestors[$description][$theirReflection->getName()])) {
return self::$ancestors[$description][$theirReflection->getName()];
if (isset(self::$ancestors[$description][$className])) {
return self::$ancestors[$description][$className];
}

$thisReflection = $this->getClassReflection();
if ($thisReflection === null) {
return null;
}

$broker = Broker::getInstance();
if (!$broker->hasClass($className)) {
return null;
}
$theirReflection = $broker->getClass($className);

if ($theirReflection->getName() === $thisReflection->getName()) {
return self::$ancestors[$description][$theirReflection->getName()] = $this;
return self::$ancestors[$description][$className] = $this;
}

foreach ($this->getInterfaces() as $interface) {
$ancestor = $interface->getAncestorWithClassName($className);
if ($ancestor !== null) {
return self::$ancestors[$description][$theirReflection->getName()] = $ancestor;
return self::$ancestors[$description][$className] = $ancestor;
}
}

$parent = $this->getParent();
if ($parent !== null) {
$ancestor = $parent->getAncestorWithClassName($className);
if ($ancestor !== null) {
return self::$ancestors[$description][$theirReflection->getName()] = $ancestor;
return self::$ancestors[$description][$className] = $ancestor;
}
}

Expand Down

0 comments on commit 1463c57

Please sign in to comment.