Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Dec 28, 2022
1 parent b1f1ca6 commit a263e5d
Showing 1 changed file with 14 additions and 34 deletions.
48 changes: 14 additions & 34 deletions src/Psalm/Internal/Type/TypeCombiner.php
Expand Up @@ -297,17 +297,14 @@ public static function combine(

foreach ($object_type->getAtomicTypes() as $object_atomic_type) {
if ($object_atomic_type instanceof TNamedObject) {
$new_types[] = new TClassString(
$object_atomic_type->value,
$object_atomic_type,
false,
false,
false,
$from_docblock,
);
$class_type = new TClassString($object_atomic_type->value, $object_atomic_type);
} elseif ($object_atomic_type instanceof TObject) {
$new_types[] = new TClassString('object', null, false, false, false, $from_docblock);
$class_type = new TClassString();
} else {
continue;
}

$new_types[] = $class_type->setFromDocblock($from_docblock);
}
}
}
Expand Down Expand Up @@ -1428,16 +1425,12 @@ private static function handleKeyedArrayEntries(
$key_type = $combination->objectlike_key_type ?? Type::getArrayKey();
$value_type = $combination->objectlike_value_type ?? Type::getMixed();
if ($combination->array_always_filled) {
$new_types[] = new TNonEmptyArray(
[$key_type, $value_type],
null,
null,
'non-empty-array',
$from_docblock,
);
$array_type = new TNonEmptyArray([$key_type, $value_type]);
} else {
$new_types[] = new TArray([$key_type, $value_type], $from_docblock);
$array_type = new TArray([$key_type, $value_type]);
}

$new_types[] = $array_type->setFromDocblock($from_docblock);
}

// if we're merging an empty array with an object-like, clobber empty array
Expand Down Expand Up @@ -1525,13 +1518,7 @@ private static function getArrayTypeFromGenericParams(
}

if ($combination->all_arrays_callable) {
$array_type = new TCallableArray(
$generic_type_params,
null,
null,
'callable-array',
$from_docblock,
);
$array_type = new TCallableArray($generic_type_params);
} elseif ($combination->array_always_filled
|| ($combination->array_sometimes_filled && $overwrite_empty_array)
|| ($combination->objectlike_entries
Expand All @@ -1549,7 +1536,6 @@ private static function getArrayTypeFromGenericParams(
null,
[Type::getInt(), $combination->array_type_params[1]],
true,
$from_docblock,
);
} elseif ($combination->array_counts && count($combination->array_counts) === 1) {
$cnt = array_keys($combination->array_counts)[0];
Expand All @@ -1563,7 +1549,6 @@ private static function getArrayTypeFromGenericParams(
null,
null,
true,
$from_docblock,
);
} else {
$cnt = $combination->array_min_counts
Expand All @@ -1581,7 +1566,6 @@ private static function getArrayTypeFromGenericParams(
null,
[Type::getListKey(), $generic_type_params[1]],
true,
$from_docblock,
);
}
} else {
Expand All @@ -1591,9 +1575,6 @@ private static function getArrayTypeFromGenericParams(
$combination->array_min_counts
? min(array_keys($combination->array_min_counts))
: null,
null,
'non-empty-array',
$from_docblock,
);
}
} else {
Expand All @@ -1605,15 +1586,14 @@ private static function getArrayTypeFromGenericParams(
array_keys($combination->class_string_map_names)[0],
array_values($combination->class_string_map_as_types)[0],
$generic_type_params[1],
$from_docblock,
);
} elseif ($combination->all_arrays_lists) {
$array_type = Type::getListAtomic($generic_type_params[1], $from_docblock);
$array_type = Type::getListAtomic($generic_type_params[1]);
} else {
$array_type = new TArray($generic_type_params, $from_docblock);
$array_type = new TArray($generic_type_params);
}
}

return $array_type;
return $array_type->setFromDocblock($from_docblock);
}
}

0 comments on commit a263e5d

Please sign in to comment.