From 93e2c3efb7181befef545fb1559179946c8509cb Mon Sep 17 00:00:00 2001 From: Oliver Hader Date: Tue, 20 Feb 2024 20:18:23 +0100 Subject: [PATCH] Avoid exceptions on fetching uninitialized names in ClassLikes 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 `[]` --- src/Psalm/Internal/Codebase/ClassLikes.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Codebase/ClassLikes.php b/src/Psalm/Internal/Codebase/ClassLikes.php index 552fab265d5..a68703a5488 100644 --- a/src/Psalm/Internal/Codebase/ClassLikes.php +++ b/src/Psalm/Internal/Codebase/ClassLikes.php @@ -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) { @@ -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; }