1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-04 18:48:03 +01:00

Simplify some logic around negations to prevent unecessary looping

This commit is contained in:
Matthew Brown 2022-01-04 16:08:06 +00:00
parent 2c6d4f8687
commit 0fffb55a83

View File

@ -176,39 +176,37 @@ class NegatedAssertionReconciler extends Reconciler
// if there wasn't a direct hit, go deeper, eliminating subtypes // if there wasn't a direct hit, go deeper, eliminating subtypes
if (!$existing_var_type->removeType($assertion)) { if (!$existing_var_type->removeType($assertion)) {
foreach ($existing_var_type->getAtomicTypes() as $part_name => $existing_var_type_part) { if (!strpos($assertion, '-')) {
if (!$existing_var_type_part->isObjectType() || strpos($assertion, '-')) {
continue;
}
$assertion_type = Type::parseString($assertion, null, $template_type_map); $assertion_type = Type::parseString($assertion, null, $template_type_map);
if (!$assertion_type->isSingle()) { if ($assertion_type->isSingle()) {
continue; $new_type_part = $assertion_type->getSingleAtomic();
}
$new_type_part = $assertion_type->getSingleAtomic(); if ($new_type_part instanceof TNamedObject) {
foreach ($existing_var_type->getAtomicTypes() as $part_name => $existing_var_type_part) {
if (!$existing_var_type_part->isObjectType()) {
continue;
}
if (!$new_type_part instanceof TNamedObject) { if (AtomicTypeComparator::isContainedBy(
continue; $codebase,
} $existing_var_type_part,
$new_type_part,
if (AtomicTypeComparator::isContainedBy( false,
$codebase, false
$existing_var_type_part, )) {
$new_type_part, $existing_var_type->removeType($part_name);
false, } elseif (AtomicTypeComparator::isContainedBy(
false $codebase,
)) { $new_type_part,
$existing_var_type->removeType($part_name); $existing_var_type_part,
} elseif (AtomicTypeComparator::isContainedBy( false,
$codebase, false
$new_type_part, )) {
$existing_var_type_part, $existing_var_type->different = true;
false, }
false }
)) { }
$existing_var_type->different = true;
} }
} }
} }