mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #1104 - allow multiple trait method aliases to map to same method
This commit is contained in:
parent
b6446824be
commit
1b740aebb5
@ -584,9 +584,11 @@ class Populator
|
||||
|
||||
if ($parent_storage->is_trait
|
||||
&& $storage->trait_alias_map
|
||||
&& isset($storage->trait_alias_map[$method_name])
|
||||
) {
|
||||
$aliased_method_names[] = $storage->trait_alias_map[$method_name];
|
||||
$aliased_method_names = array_merge(
|
||||
$aliased_method_names,
|
||||
array_keys($storage->trait_alias_map, $method_name, true)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($aliased_method_names as $aliased_method_name) {
|
||||
@ -627,9 +629,11 @@ class Populator
|
||||
|
||||
if ($parent_storage->is_trait
|
||||
&& $storage->trait_alias_map
|
||||
&& isset($storage->trait_alias_map[$method_name])
|
||||
) {
|
||||
$aliased_method_names[] = $storage->trait_alias_map[$method_name];
|
||||
$aliased_method_names = array_merge(
|
||||
$aliased_method_names,
|
||||
array_keys($storage->trait_alias_map, $method_name, true)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($aliased_method_names as $aliased_method_name) {
|
||||
|
@ -391,7 +391,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
foreach ($node->adaptations as $adaptation) {
|
||||
if ($adaptation instanceof PhpParser\Node\Stmt\TraitUseAdaptation\Alias) {
|
||||
if ($adaptation->newName) {
|
||||
$method_map[strtolower($adaptation->method->name)] = strtolower($adaptation->newName->name);
|
||||
$method_map[strtolower($adaptation->newName->name)] = strtolower($adaptation->method->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -661,6 +661,42 @@ class TraitTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'manyTraitAliases' => [
|
||||
'<?php
|
||||
trait Foo {
|
||||
public static function staticMethod():void {}
|
||||
public function nonstatic():void {}
|
||||
}
|
||||
|
||||
Class Bar {
|
||||
use Foo {
|
||||
Foo::staticMethod as foo;
|
||||
Foo::staticMethod as foobar;
|
||||
Foo::staticMethod as fine;
|
||||
Foo::nonstatic as bad;
|
||||
Foo::nonstatic as good;
|
||||
}
|
||||
}
|
||||
|
||||
$b = new Bar();
|
||||
|
||||
Bar::fine();
|
||||
$b::fine();
|
||||
$b->fine();
|
||||
|
||||
$b->good();
|
||||
|
||||
Bar::foo();
|
||||
Bar::foobar();
|
||||
|
||||
$b::foo();
|
||||
$b::foobar();
|
||||
|
||||
$b->foo();
|
||||
$b->foobar();
|
||||
|
||||
$b->bad();'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user