1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Simplify isset reconciliation slightly

This commit is contained in:
Matthew Brown 2022-01-01 16:01:27 +00:00
parent 6c176bbdb5
commit 387f2664f7

View File

@ -81,61 +81,54 @@ class SimpleNegatedAssertionReconciler extends Reconciler
if (!$existing_var_type->isNullable() if (!$existing_var_type->isNullable()
&& $key && $key
&& strpos($key, '[') === false && strpos($key, '[') === false
&& (!$existing_var_type->hasMixed() || $existing_var_type->isAlwaysTruthy())
) { ) {
foreach ($existing_var_type->getAtomicTypes() as $atomic) { if ($code_location) {
if (!$existing_var_type->hasMixed() if ($existing_var_type->from_static_property) {
|| $atomic instanceof TNonEmptyMixed IssueBuffer::maybeAdd(
) { new RedundantPropertyInitializationCheck(
$failed_reconciliation = Reconciler::RECONCILIATION_EMPTY; 'Static property ' . $key . ' with type '
. $existing_var_type
if ($code_location) { . ' has unexpected isset check — should it be nullable?',
if ($existing_var_type->from_static_property) { $code_location
IssueBuffer::maybeAdd( ),
new RedundantPropertyInitializationCheck( $suppressed_issues
'Static property ' . $key . ' with type ' );
. $existing_var_type } elseif ($existing_var_type->from_property) {
. ' has unexpected isset check — should it be nullable?', IssueBuffer::maybeAdd(
$code_location new RedundantPropertyInitializationCheck(
), 'Property ' . $key . ' with type '
$suppressed_issues . $existing_var_type . ' should already be set in the constructor',
); $code_location
} elseif ($existing_var_type->from_property) { ),
IssueBuffer::maybeAdd( $suppressed_issues
new RedundantPropertyInitializationCheck( );
'Property ' . $key . ' with type ' } elseif ($existing_var_type->from_docblock) {
. $existing_var_type . ' should already be set in the constructor', IssueBuffer::maybeAdd(
$code_location new DocblockTypeContradiction(
), 'Cannot resolve types for ' . $key . ' with docblock-defined type '
$suppressed_issues . $existing_var_type . ' and !isset assertion',
); $code_location,
} elseif ($existing_var_type->from_docblock) { null
IssueBuffer::maybeAdd( ),
new DocblockTypeContradiction( $suppressed_issues
'Cannot resolve types for ' . $key . ' with docblock-defined type ' );
. $existing_var_type . ' and !isset assertion', } else {
$code_location, IssueBuffer::maybeAdd(
null new TypeDoesNotContainType(
), 'Cannot resolve types for ' . $key . ' with type '
$suppressed_issues . $existing_var_type . ' and !isset assertion',
); $code_location,
} else { null
IssueBuffer::maybeAdd( ),
new TypeDoesNotContainType( $suppressed_issues
'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 $existing_var_type->from_docblock
? Type::getNull()
: Type::getEmpty();
} }
return Type::getNull(); return Type::getNull();