1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-04 10:38:49 +01:00

qa: refactor code to avoid too many nesting levels

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
This commit is contained in:
Maximilian Bösing 2022-06-12 19:27:54 +02:00
parent 7e033d8051
commit 3fd7a8b6d7
No known key found for this signature in database
GPG Key ID: 9A8988C93CEC81A3

View File

@ -795,8 +795,9 @@ class CallAnalyzer
}
} elseif (isset($context->vars_in_scope[$assertion_var_id])) {
$other_type = $context->vars_in_scope[$assertion_var_id];
if (self::isNewTypeNarrowingDownOldType($other_type, $union)) {
$union = self::createUnionIntersectionFromOldType($union, $other_type);
$union = self::createUnionIntersectionFromOldType($union, $other_type);
if ($union !== null) {
foreach ($union->getAtomicTypes() as $atomic_type) {
if ($assertion_type instanceof TTemplateParam
&& $assertion_type->as->getId() === $atomic_type->getId()
@ -1180,8 +1181,12 @@ class CallAnalyzer
* If another assertion takes place to determine if the value is either "a", "c" or "d", we can kick "d" as that
* won't be possible.
*/
private static function createUnionIntersectionFromOldType(Union $new_type, Union $old_type): Union
private static function createUnionIntersectionFromOldType(Union $new_type, Union $old_type): ?Union
{
if (!self::isNewTypeNarrowingDownOldType($old_type, $new_type)) {
return null;
}
if (!$new_type->allLiterals() || !$old_type->allLiterals()) {
return $new_type;
}
@ -1198,6 +1203,10 @@ class CallAnalyzer
}
}
if ($equal_atomic_types === []) {
return null;
}
return new Union($equal_atomic_types);
}
}