1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix class_alias treatment for interfaces and others

This commit is contained in:
Matthew Brown 2018-12-21 09:29:23 -05:00
parent 02003d9996
commit e744e71946
5 changed files with 33 additions and 7 deletions

View File

@ -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]);
}

View File

@ -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;

View File

@ -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;

View File

@ -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());

View File

@ -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);
}