mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #6327 from boesing/bugfix/class-alias
This commit is contained in:
commit
e5b797c764
@ -675,7 +675,21 @@ 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 ($class_storage->class_implements as $implementing_interface_lc => $_) {
|
||||
$aliased_interface_lc = strtolower(
|
||||
$this->getUnAliasedName($implementing_interface_lc)
|
||||
);
|
||||
|
||||
if ($aliased_interface_lc === $interface_id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function interfaceExists(
|
||||
|
41
tests/Internal/Codebase/ClassLikesTest.php
Normal file
41
tests/Internal/Codebase/ClassLikesTest.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psalm\Tests\Internal\Codebase;
|
||||
|
||||
use Psalm\Internal\Codebase\ClassLikes;
|
||||
use Psalm\Internal\Provider\ClassLikeStorageProvider;
|
||||
use Psalm\Storage\ClassLikeStorage;
|
||||
use Psalm\Tests\TestCase;
|
||||
|
||||
final class ClassLikesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ClassLikes
|
||||
*/
|
||||
private $classlikes;
|
||||
|
||||
/**
|
||||
* @var ClassLikeStorageProvider
|
||||
*/
|
||||
private $storage_provider;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->classlikes = $this->project_analyzer->getCodebase()->classlikes;
|
||||
$this->storage_provider = $this->project_analyzer->getCodebase()->classlike_storage_provider;
|
||||
}
|
||||
|
||||
public function testWillDetectClassImplementingAliasedInterface(): void
|
||||
{
|
||||
$this->classlikes->addClassAlias('Foo', 'bar');
|
||||
|
||||
$classStorage = new ClassLikeStorage('Baz');
|
||||
$classStorage->class_implements['bar'] = 'Bar';
|
||||
|
||||
$this->storage_provider->addMore(['baz' => $classStorage]);
|
||||
|
||||
self::assertTrue($this->classlikes->classImplements('Baz', 'Foo'));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user