1
0
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:
Bruce Weirdan 2021-08-17 23:35:25 +03:00 committed by GitHub
commit e5b797c764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 1 deletions

View File

@ -675,7 +675,21 @@ class ClassLikes
} }
$class_storage = $this->classlike_storage_provider->get($fq_class_name); $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( public function interfaceExists(

View 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'));
}
}