From f8db5a0461045db909dd027789a26b827fd69ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20B=C3=B6sing?= <2189546+boesing@users.noreply.github.com> Date: Tue, 17 Aug 2021 18:16:37 +0200 Subject: [PATCH] bugfix: enable `ClassLikes` to properly detect implementing class aliases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com> --- src/Psalm/Internal/Codebase/ClassLikes.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Codebase/ClassLikes.php b/src/Psalm/Internal/Codebase/ClassLikes.php index 6559f49a6..bb59ef9b4 100644 --- a/src/Psalm/Internal/Codebase/ClassLikes.php +++ b/src/Psalm/Internal/Codebase/ClassLikes.php @@ -26,6 +26,7 @@ use Psalm\Storage\ClassLikeStorage; use Psalm\Type; use ReflectionProperty; +use function array_keys; use function array_merge; use function array_pop; use function count; @@ -675,7 +676,23 @@ class ClassLikes } $class_storage = $this->classlike_storage_provider->get($fq_class_name); - return isset($class_storage->class_implements[$interface_id]); + if (isset($class_storage->class_implements[$interface_id])) { + return true; + } + + foreach (array_keys($class_storage->class_implements) as $implementing_interface_lc) { + if (!isset($this->classlike_aliases[$implementing_interface_lc])) { + continue; + } + + $aliased_interface_lc = strtolower($this->classlike_aliases[$implementing_interface_lc]); + + if ($aliased_interface_lc === $interface_id) { + return true; + } + } + + return false; } public function interfaceExists(