Skip to content

Commit

Permalink
Avoid exceptions on fetching uninitialized names in ClassLikes
Browse files Browse the repository at this point in the history
Similar to the behavior of `ClassLikes::classImplements()` (#5984),
the following methods will return a false/empty value in case a
specific class name has not been initialized yet:

+ `ClassLikes::classExtends()` returns `false`
+ `ClassLikes::getParentInterfaces()` returns `[]`
  • Loading branch information
ohader committed Feb 20, 2024
1 parent b0e6db1 commit 93e2c3e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Psalm/Internal/Codebase/ClassLikes.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,9 @@ public function classExtends(string $fq_class_name, string $possible_parent, boo
return false;
}

if (!$this->classlike_storage_provider->has($unaliased_fq_class_name)) {
return false;
}
$class_storage = $this->classlike_storage_provider->get($unaliased_fq_class_name);

if ($from_api && !$class_storage->populated) {
Expand Down Expand Up @@ -722,7 +725,9 @@ public function interfaceExtends(string $interface_name, string $possible_parent
public function getParentInterfaces(string $fq_interface_name): array
{
$fq_interface_name = strtolower($fq_interface_name);

if (!$this->classlike_storage_provider->has($fq_interface_name)) {
return [];
}
return $this->classlike_storage_provider->get($fq_interface_name)->parent_interfaces;
}

Expand Down

0 comments on commit 93e2c3e

Please sign in to comment.