mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
commit
1cde7e4031
@ -6,11 +6,14 @@ use Psalm\Codebase;
|
||||
use Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer;
|
||||
use Psalm\Type\Atomic;
|
||||
use Psalm\Type\Atomic\TIterable;
|
||||
use Psalm\Type\Atomic\TMixed;
|
||||
use Psalm\Type\Atomic\TNamedObject;
|
||||
use Psalm\Type\Atomic\TObjectWithProperties;
|
||||
use Psalm\Type\Atomic\TTemplateParam;
|
||||
use Psalm\Type\Union;
|
||||
|
||||
use function count;
|
||||
use function current;
|
||||
use function in_array;
|
||||
use function strpos;
|
||||
use function strtolower;
|
||||
@ -31,6 +34,28 @@ class ObjectComparator
|
||||
bool $allow_interface_equality,
|
||||
?TypeComparisonResult $atomic_comparison_result
|
||||
): bool {
|
||||
if ($container_type_part instanceof TTemplateParam
|
||||
&& $input_type_part instanceof TTemplateParam
|
||||
&& $container_type_part->defining_class != $input_type_part->defining_class
|
||||
&& strpos($container_type_part->defining_class, 'fn-') !== 0
|
||||
&& strpos($input_type_part->defining_class, 'fn-') !== 0
|
||||
&& 1 == count($container_type_part->as->getAtomicTypes())
|
||||
&& 1 == count($input_type_part->as->getAtomicTypes())) {
|
||||
$containerAs = current($container_type_part->as->getAtomicTypes());
|
||||
$inputAs = current($input_type_part->as->getAtomicTypes());
|
||||
if ($containerAs instanceof TNamedObject && $inputAs instanceof TNamedObject) {
|
||||
return self::isShallowlyContainedBy(
|
||||
$codebase,
|
||||
$inputAs,
|
||||
$containerAs,
|
||||
$allow_interface_equality,
|
||||
$atomic_comparison_result,
|
||||
);
|
||||
} elseif ($containerAs instanceof TMixed && $inputAs instanceof TMixed) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$intersection_input_types = self::getIntersectionTypes($input_type_part);
|
||||
$intersection_container_types = self::getIntersectionTypes($container_type_part);
|
||||
|
||||
|
@ -1635,9 +1635,6 @@ class ClassTemplateExtendsTest extends TestCase
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
/**
|
||||
* @psalm-suppress InvalidReturnStatement
|
||||
*/
|
||||
return new ArrayIterator($this->elements);
|
||||
}
|
||||
|
||||
|
@ -121,6 +121,129 @@ class NestedTemplateTest extends TestCase
|
||||
return reset($arr);
|
||||
}',
|
||||
],
|
||||
'3levelNestedTemplatesOfMixed' => [
|
||||
'code' => '<?php
|
||||
/** @template T */
|
||||
interface A {}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template U of A<T>
|
||||
*/
|
||||
interface B {}
|
||||
|
||||
/** @template T */
|
||||
interface J {}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template U of A<T>
|
||||
* @implements J<U>
|
||||
*/
|
||||
class K2 implements J {}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template U of A<T>
|
||||
* @template V of B<T, U>
|
||||
* @extends J<V>
|
||||
*/
|
||||
interface K3 extends J {}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template U of A<T>
|
||||
* @template V of B<T, U>
|
||||
* @implements J<V>
|
||||
*/
|
||||
class K1 implements J {}',
|
||||
],
|
||||
'4levelNestedTemplatesOfObjects' => [
|
||||
'code' => '<?php
|
||||
/**
|
||||
* Interface for all DB entities that map to some data-model object.
|
||||
*
|
||||
* @template T
|
||||
*/
|
||||
interface DbEntity
|
||||
{
|
||||
/**
|
||||
* Maps this entity to a data-model entity
|
||||
*
|
||||
* @return T Data-model entity to which this DB entity maps.
|
||||
*/
|
||||
public function toCore();
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T of object
|
||||
*/
|
||||
abstract class EntityRepository {}
|
||||
|
||||
/**
|
||||
* Base entity repository with common tooling.
|
||||
*
|
||||
* @template T of object
|
||||
* @extends EntityRepository<T>
|
||||
*/
|
||||
abstract class DbEntityRepository
|
||||
extends EntityRepository {}
|
||||
|
||||
interface ObjectId {}
|
||||
|
||||
/**
|
||||
* @template I of ObjectId
|
||||
*/
|
||||
interface AnObject {}
|
||||
|
||||
/**
|
||||
* Base entity repository with common tooling.
|
||||
*
|
||||
* @template I of ObjectId
|
||||
* @template O of AnObject<I>
|
||||
* @template E of DbEntity<O>
|
||||
* @extends DbEntityRepository<E>
|
||||
*/
|
||||
abstract class AnObjectEntityRepository
|
||||
extends DbEntityRepository
|
||||
{}
|
||||
|
||||
/**
|
||||
* Base repository implementation backed by a Db repository.
|
||||
*
|
||||
* @template T
|
||||
* @template E of DbEntity<T>
|
||||
* @template R of DbEntityRepository<E>
|
||||
*/
|
||||
abstract class DbRepositoryWrapper
|
||||
{
|
||||
/** @var R $repo Db repository */
|
||||
private DbEntityRepository $repo;
|
||||
|
||||
/**
|
||||
* Getter for the Db repository.
|
||||
*
|
||||
* @return DbEntityRepository The Db repository.
|
||||
* @psalm-return R
|
||||
*/
|
||||
protected function getDbRepo(): DbEntityRepository
|
||||
{
|
||||
return $this->repo;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base implementation for all custom repositories that map to Core objects.
|
||||
*
|
||||
* @template I of ObjectId
|
||||
* @template O of AnObject<I>
|
||||
* @template E of DbEntity<O>
|
||||
* @template R of AnObjectEntityRepository<I, O, E>
|
||||
* @extends DbRepositoryWrapper<O, E, R>
|
||||
*/
|
||||
abstract class AnObjectDbRepositoryWrapper
|
||||
extends DbRepositoryWrapper {}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user