1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Improve min/max return type cc @orklah

Type::combineUnionTypes preserves metadata for union types, and is more accurate
This commit is contained in:
Matt Brown 2021-03-13 19:28:24 -05:00
parent b549989ba7
commit f1a840727d

View File

@ -37,21 +37,23 @@ class MinMaxReturnTypeProvider implements FunctionReturnTypeProviderInterface
return $array_type->value;
}
$atomics = [];
$return_type = null;
foreach ($call_args as $arg) {
if ($array_arg_type = $nodeTypeProvider->getType($arg->value)) {
foreach ($array_arg_type->getAtomicTypes() as $atomicType) {
$atomics[] = $atomicType;
if (!$return_type) {
$return_type = $array_arg_type;
} else {
$return_type = \Psalm\Type::combineUnionTypes(
$return_type,
$array_arg_type
);
}
} else {
return Type::getMixed();
}
}
if ($atomics === []) {
return Type::getMixed();
}
return new Type\Union($atomics);
return $return_type;
}
}