Skip to content

Commit

Permalink
Simplify isset reconciliation slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 1, 2022
1 parent 6c176bb commit 387f266
Showing 1 changed file with 45 additions and 52 deletions.
97 changes: 45 additions & 52 deletions src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,61 +81,54 @@ public static function reconcile(
if (!$existing_var_type->isNullable()
&& $key
&& strpos($key, '[') === false
&& (!$existing_var_type->hasMixed() || $existing_var_type->isAlwaysTruthy())
) {
foreach ($existing_var_type->getAtomicTypes() as $atomic) {
if (!$existing_var_type->hasMixed()
|| $atomic instanceof TNonEmptyMixed
) {
$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY;

if ($code_location) {
if ($existing_var_type->from_static_property) {
IssueBuffer::maybeAdd(
new RedundantPropertyInitializationCheck(
'Static property ' . $key . ' with type '
. $existing_var_type
. ' has unexpected isset check — should it be nullable?',
$code_location
),
$suppressed_issues
);
} elseif ($existing_var_type->from_property) {
IssueBuffer::maybeAdd(
new RedundantPropertyInitializationCheck(
'Property ' . $key . ' with type '
. $existing_var_type . ' should already be set in the constructor',
$code_location
),
$suppressed_issues
);
} elseif ($existing_var_type->from_docblock) {
IssueBuffer::maybeAdd(
new DocblockTypeContradiction(
'Cannot resolve types for ' . $key . ' with docblock-defined type '
. $existing_var_type . ' and !isset assertion',
$code_location,
null
),
$suppressed_issues
);
} else {
IssueBuffer::maybeAdd(
new TypeDoesNotContainType(
'Cannot resolve types for ' . $key . ' with type '
. $existing_var_type . ' and !isset assertion',
$code_location,
null
),
$suppressed_issues
);
}
}

return $existing_var_type->from_docblock
? Type::getNull()
: Type::getEmpty();
if ($code_location) {
if ($existing_var_type->from_static_property) {
IssueBuffer::maybeAdd(
new RedundantPropertyInitializationCheck(
'Static property ' . $key . ' with type '
. $existing_var_type
. ' has unexpected isset check — should it be nullable?',
$code_location
),
$suppressed_issues
);
} elseif ($existing_var_type->from_property) {
IssueBuffer::maybeAdd(
new RedundantPropertyInitializationCheck(
'Property ' . $key . ' with type '
. $existing_var_type . ' should already be set in the constructor',
$code_location
),
$suppressed_issues
);
} elseif ($existing_var_type->from_docblock) {
IssueBuffer::maybeAdd(
new DocblockTypeContradiction(
'Cannot resolve types for ' . $key . ' with docblock-defined type '
. $existing_var_type . ' and !isset assertion',
$code_location,
null
),
$suppressed_issues
);
} else {
IssueBuffer::maybeAdd(
new TypeDoesNotContainType(
'Cannot resolve types for ' . $key . ' with type '
. $existing_var_type . ' and !isset assertion',
$code_location,
null
),
$suppressed_issues
);
}
}

return $existing_var_type->from_docblock
? Type::getNull()
: Type::getEmpty();
}

return Type::getNull();
Expand Down

0 comments on commit 387f266

Please sign in to comment.