mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Remove never-used function
This commit is contained in:
parent
3a2fa99969
commit
04758a48c6
@ -1051,179 +1051,6 @@ class TypeChecker
|
||||
return $result_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasIdenticalTypes(
|
||||
Codebase $codebase,
|
||||
Type\Union $declared_type,
|
||||
Type\Union $inferred_type
|
||||
) {
|
||||
if ($declared_type->isMixed() || $inferred_type->isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($declared_type->isNullable() !== $inferred_type->isNullable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$simple_declared_types = array_filter(
|
||||
array_keys($declared_type->getTypes()),
|
||||
/**
|
||||
* @param string $type_value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ($type_value) {
|
||||
return $type_value !== 'null';
|
||||
}
|
||||
);
|
||||
|
||||
$simple_inferred_types = array_filter(
|
||||
array_keys($inferred_type->getTypes()),
|
||||
/**
|
||||
* @param string $type_value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ($type_value) {
|
||||
return $type_value !== 'null';
|
||||
}
|
||||
);
|
||||
|
||||
// gets elements A△B
|
||||
$differing_types = array_diff($simple_inferred_types, $simple_declared_types);
|
||||
|
||||
if (!empty($differing_types)) {
|
||||
// check whether the differing types are subclasses of declared return types
|
||||
foreach ($differing_types as $differing_type) {
|
||||
$is_match = false;
|
||||
|
||||
if ($differing_type === 'mixed') {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($simple_declared_types as $simple_declared_type) {
|
||||
if ($simple_declared_type === 'mixed') {
|
||||
$is_match = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (strtolower($simple_declared_type) === 'callable' && strtolower($differing_type) === 'closure') {
|
||||
$is_match = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset(ClassLikeChecker::$SPECIAL_TYPES[strtolower($simple_declared_type)]) ||
|
||||
isset(ClassLikeChecker::$SPECIAL_TYPES[strtolower($differing_type)])
|
||||
) {
|
||||
if (in_array($differing_type, ['float', 'int'], true) &&
|
||||
in_array($simple_declared_type, ['float', 'int'], true)
|
||||
) {
|
||||
$is_match = true;
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$codebase->classOrInterfaceExists($differing_type)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($simple_declared_type === 'object') {
|
||||
$is_match = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$codebase->classOrInterfaceExists($simple_declared_type)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($codebase->classExtendsOrImplements($differing_type, $simple_declared_type)) {
|
||||
$is_match = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if ($codebase->interfaceExists($differing_type) &&
|
||||
$codebase->interfaceExtends($differing_type, $simple_declared_type)
|
||||
) {
|
||||
$is_match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$is_match) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($declared_type->getTypes() as $key => $declared_atomic_type) {
|
||||
if (!isset($inferred_type->getTypes()[$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$inferred_atomic_type = $inferred_type->getTypes()[$key];
|
||||
|
||||
if (!$declared_atomic_type instanceof Type\Atomic\TArray &&
|
||||
!$declared_atomic_type instanceof Type\Atomic\TGenericObject
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$inferred_atomic_type instanceof Type\Atomic\TArray &&
|
||||
!$inferred_atomic_type instanceof Type\Atomic\TGenericObject
|
||||
) {
|
||||
// @todo handle this better
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($declared_atomic_type->type_params as $offset => $type_param) {
|
||||
if (!self::hasIdenticalTypes(
|
||||
$codebase,
|
||||
$type_param,
|
||||
$inferred_atomic_type->type_params[$offset]
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($declared_type->getTypes() as $key => $declared_atomic_type) {
|
||||
if (!isset($inferred_type->getTypes()[$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$inferred_atomic_type = $inferred_type->getTypes()[$key];
|
||||
|
||||
if (!($declared_atomic_type instanceof Type\Atomic\ObjectLike)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!($inferred_atomic_type instanceof Type\Atomic\ObjectLike)) {
|
||||
// @todo handle this better
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($declared_atomic_type->properties as $property_name => $type_param) {
|
||||
if (!isset($inferred_atomic_type->properties[$property_name])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!self::hasIdenticalTypes(
|
||||
$codebase,
|
||||
$type_param,
|
||||
$inferred_atomic_type->properties[$property_name]
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Type\Union
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user