diff --git a/src/Psalm/Internal/Codebase/ClassLikes.php b/src/Psalm/Internal/Codebase/ClassLikes.php index 61cd57daf..8654a213b 100644 --- a/src/Psalm/Internal/Codebase/ClassLikes.php +++ b/src/Psalm/Internal/Codebase/ClassLikes.php @@ -298,7 +298,7 @@ class ClassLikes $fq_class_name_lc = strtolower($fq_class_name); if (isset($this->classlike_aliases[$fq_class_name_lc])) { - $fq_class_name_lc = $this->classlike_aliases[$fq_class_name_lc]; + $fq_class_name_lc = strtolower($this->classlike_aliases[$fq_class_name_lc]); } if (!isset($this->existing_interfaces_lc[$fq_class_name_lc]) @@ -344,7 +344,7 @@ class ClassLikes $fq_class_name_lc = strtolower($fq_class_name); if (isset($this->classlike_aliases[$fq_class_name_lc])) { - $fq_class_name_lc = $this->classlike_aliases[$fq_class_name_lc]; + $fq_class_name_lc = strtolower($this->classlike_aliases[$fq_class_name_lc]); } if (!isset($this->existing_traits_lc[$fq_class_name_lc]) || @@ -559,6 +559,10 @@ class ClassLikes return true; } + if (isset($this->classlike_aliases[strtolower($fq_interface_name)])) { + return true; + } + return isset($this->existing_interfaces[$fq_interface_name]); } diff --git a/src/Psalm/Internal/Codebase/Populator.php b/src/Psalm/Internal/Codebase/Populator.php index 996fb1a75..1f2b7bdaf 100644 --- a/src/Psalm/Internal/Codebase/Populator.php +++ b/src/Psalm/Internal/Codebase/Populator.php @@ -289,6 +289,9 @@ class Populator ) { foreach ($storage->used_traits as $used_trait_lc => $_) { try { + $used_trait_lc = $this->classlikes->getUnAliasedName( + $used_trait_lc + ); $trait_storage = $storage_provider->get($used_trait_lc); } catch (\InvalidArgumentException $e) { continue; @@ -312,6 +315,9 @@ class Populator $parent_storage_class = reset($storage->parent_classes); try { + $parent_storage_class = $this->classlikes->getUnAliasedName( + strtolower($parent_storage_class) + ); $parent_storage = $storage_provider->get($parent_storage_class); } catch (\InvalidArgumentException $e) { $storage->invalid_dependencies[] = $parent_storage_class; @@ -364,6 +370,9 @@ class Populator foreach ($storage->parent_interfaces as $parent_interface_lc => $_) { try { + $parent_interface_lc = $this->classlikes->getUnAliasedName( + $parent_interface_lc + ); $parent_interface_storage = $storage_provider->get($parent_interface_lc); } catch (\InvalidArgumentException $e) { $storage->invalid_dependencies[] = $parent_interface_lc; @@ -403,6 +412,9 @@ class Populator foreach ($storage->class_implements as $implemented_interface_lc => $_) { try { + $implemented_interface_lc = $this->classlikes->getUnAliasedName( + strtolower($implemented_interface_lc) + ); $implemented_interface_storage = $storage_provider->get($implemented_interface_lc); } catch (\InvalidArgumentException $e) { $storage->invalid_dependencies[] = $implemented_interface_lc; @@ -431,6 +443,9 @@ class Populator foreach ($storage->class_implements as $implemented_interface) { try { + $implemented_interface = $this->classlikes->getUnAliasedName( + strtolower($implemented_interface) + ); $implemented_interface_storage = $storage_provider->get($implemented_interface); } catch (\InvalidArgumentException $e) { continue; diff --git a/src/Psalm/Internal/Codebase/Scanner.php b/src/Psalm/Internal/Codebase/Scanner.php index c5fde4904..43f7349ff 100644 --- a/src/Psalm/Internal/Codebase/Scanner.php +++ b/src/Psalm/Internal/Codebase/Scanner.php @@ -721,7 +721,7 @@ class Scanner $new_fq_class_name = $reflected_class->getName(); if (strtolower($new_fq_class_name) !== strtolower($fq_class_name)) { - $classlikes->addClassAlias($new_fq_class_name, $fq_class_name); + $classlikes->addClassAlias($new_fq_class_name, strtolower($fq_class_name)); } $fq_class_name = $new_fq_class_name; diff --git a/tests/StubTest.php b/tests/StubTest.php index ad2907394..78db18712 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -369,7 +369,9 @@ class StubTest extends TestCase return f(); } - $d = new D();' + $d = new D(); + + class E implements IAlias {}' ); $this->analyzeFile($file_path, new Context()); diff --git a/tests/stubs/class_alias.php b/tests/stubs/class_alias.php index fe0a6b9b3..9ae353f9c 100644 --- a/tests/stubs/class_alias.php +++ b/tests/stubs/class_alias.php @@ -13,12 +13,17 @@ class A { } } +interface I {} + class_alias("ClassAliasStubTest\\A", "ClassAliasStubTest\\B"); class_alias(A::class, C::class); $arr = [ - [A::class, D::class] + [A::class, D::class], + [I::class, IAlias::class], ]; -// Psalm cannot reason about this in the loading step -class_alias($arr[0][0], $arr[0][1]); +foreach ($arr as list($orig, $alias)) { + // Psalm cannot reason about this in the loading step + class_alias($orig, $alias); +}