1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 08:49:52 +01:00

Experiment with refactor

This commit is contained in:
Matt Brown 2020-11-10 12:50:17 -05:00
parent b731b53d5e
commit a82a9558d2

View File

@ -577,13 +577,6 @@ class AssertionFinder
$if_types = []; $if_types = [];
$null_position = self::hasNullVariable($conditional, $source); $null_position = self::hasNullVariable($conditional, $source);
$false_position = self::hasFalseVariable($conditional);
$true_position = self::hasTrueVariable($conditional);
$empty_array_position = self::hasEmptyArrayVariable($conditional);
$gettype_position = self::hasGetTypeCheck($conditional);
$get_debug_type_position = self::hasGetDebugTypeCheck($conditional);
$min_count = null;
$count_equality_position = self::hasNonEmptyCountEqualityCheck($conditional, $min_count);
if ($null_position !== null) { if ($null_position !== null) {
if ($null_position === self::ASSIGNMENT_TO_RIGHT) { if ($null_position === self::ASSIGNMENT_TO_RIGHT) {
@ -657,6 +650,8 @@ class AssertionFinder
return $if_types ? [$if_types] : []; return $if_types ? [$if_types] : [];
} }
$true_position = self::hasTrueVariable($conditional);
if ($true_position) { if ($true_position) {
if ($true_position === self::ASSIGNMENT_TO_RIGHT) { if ($true_position === self::ASSIGNMENT_TO_RIGHT) {
$base_conditional = $conditional->left; $base_conditional = $conditional->left;
@ -775,6 +770,8 @@ class AssertionFinder
return $if_types; return $if_types;
} }
$false_position = self::hasFalseVariable($conditional);
if ($false_position) { if ($false_position) {
if ($false_position === self::ASSIGNMENT_TO_RIGHT) { if ($false_position === self::ASSIGNMENT_TO_RIGHT) {
$base_conditional = $conditional->left; $base_conditional = $conditional->left;
@ -884,6 +881,8 @@ class AssertionFinder
return $if_types; return $if_types;
} }
$empty_array_position = self::hasEmptyArrayVariable($conditional);
if ($empty_array_position !== null) { if ($empty_array_position !== null) {
if ($empty_array_position === self::ASSIGNMENT_TO_RIGHT) { if ($empty_array_position === self::ASSIGNMENT_TO_RIGHT) {
$base_conditional = $conditional->left; $base_conditional = $conditional->left;
@ -948,6 +947,8 @@ class AssertionFinder
return $if_types ? [$if_types] : []; return $if_types ? [$if_types] : [];
} }
$gettype_position = self::hasGetTypeCheck($conditional);
if ($gettype_position) { if ($gettype_position) {
if ($gettype_position === self::ASSIGNMENT_TO_RIGHT) { if ($gettype_position === self::ASSIGNMENT_TO_RIGHT) {
$string_expr = $conditional->left; $string_expr = $conditional->left;
@ -987,6 +988,8 @@ class AssertionFinder
return $if_types ? [$if_types] : []; return $if_types ? [$if_types] : [];
} }
$get_debug_type_position = self::hasGetDebugTypeCheck($conditional);
if ($get_debug_type_position) { if ($get_debug_type_position) {
if ($get_debug_type_position === self::ASSIGNMENT_TO_RIGHT) { if ($get_debug_type_position === self::ASSIGNMENT_TO_RIGHT) {
$whichclass_expr = $conditional->left; $whichclass_expr = $conditional->left;
@ -1033,6 +1036,9 @@ class AssertionFinder
return $if_types ? [$if_types] : []; return $if_types ? [$if_types] : [];
} }
$min_count = null;
$count_equality_position = self::hasNonEmptyCountEqualityCheck($conditional, $min_count);
if ($count_equality_position) { if ($count_equality_position) {
if ($count_equality_position === self::ASSIGNMENT_TO_RIGHT) { if ($count_equality_position === self::ASSIGNMENT_TO_RIGHT) {
$count_expr = $conditional->left; $count_expr = $conditional->left;
@ -1268,13 +1274,6 @@ class AssertionFinder
$if_types = []; $if_types = [];
$null_position = self::hasNullVariable($conditional, $source); $null_position = self::hasNullVariable($conditional, $source);
$false_position = self::hasFalseVariable($conditional);
$true_position = self::hasTrueVariable($conditional);
$empty_array_position = self::hasEmptyArrayVariable($conditional);
$gettype_position = self::hasGetTypeCheck($conditional);
$get_debug_type_position = self::hasGetDebugTypeCheck($conditional);
$count = null;
$count_inequality_position = self::hasNotCountEqualityCheck($conditional, $count);
if ($null_position !== null) { if ($null_position !== null) {
if ($null_position === self::ASSIGNMENT_TO_RIGHT) { if ($null_position === self::ASSIGNMENT_TO_RIGHT) {
@ -1349,6 +1348,8 @@ class AssertionFinder
return $if_types ? [$if_types] : []; return $if_types ? [$if_types] : [];
} }
$false_position = self::hasFalseVariable($conditional);
if ($false_position) { if ($false_position) {
if ($false_position === self::ASSIGNMENT_TO_RIGHT) { if ($false_position === self::ASSIGNMENT_TO_RIGHT) {
$base_conditional = $conditional->left; $base_conditional = $conditional->left;
@ -1450,6 +1451,8 @@ class AssertionFinder
return $if_types ? [$if_types] : []; return $if_types ? [$if_types] : [];
} }
$true_position = self::hasTrueVariable($conditional);
if ($true_position) { if ($true_position) {
if ($true_position === self::ASSIGNMENT_TO_RIGHT) { if ($true_position === self::ASSIGNMENT_TO_RIGHT) {
$base_conditional = $conditional->left; $base_conditional = $conditional->left;
@ -1563,6 +1566,9 @@ class AssertionFinder
return $if_types; return $if_types;
} }
$count = null;
$count_inequality_position = self::hasNotCountEqualityCheck($conditional, $count);
if ($count_inequality_position) { if ($count_inequality_position) {
if ($count_inequality_position === self::ASSIGNMENT_TO_RIGHT) { if ($count_inequality_position === self::ASSIGNMENT_TO_RIGHT) {
$count_expr = $conditional->left; $count_expr = $conditional->left;
@ -1590,6 +1596,8 @@ class AssertionFinder
return $if_types ? [$if_types] : []; return $if_types ? [$if_types] : [];
} }
$empty_array_position = self::hasEmptyArrayVariable($conditional);
if ($empty_array_position !== null) { if ($empty_array_position !== null) {
if ($empty_array_position === self::ASSIGNMENT_TO_RIGHT) { if ($empty_array_position === self::ASSIGNMENT_TO_RIGHT) {
$base_conditional = $conditional->left; $base_conditional = $conditional->left;
@ -1659,6 +1667,8 @@ class AssertionFinder
return $if_types ? [$if_types] : []; return $if_types ? [$if_types] : [];
} }
$gettype_position = self::hasGetTypeCheck($conditional);
if ($gettype_position) { if ($gettype_position) {
if ($gettype_position === self::ASSIGNMENT_TO_RIGHT) { if ($gettype_position === self::ASSIGNMENT_TO_RIGHT) {
$whichclass_expr = $conditional->left; $whichclass_expr = $conditional->left;
@ -1708,6 +1718,8 @@ class AssertionFinder
return $if_types ? [$if_types] : []; return $if_types ? [$if_types] : [];
} }
$get_debug_type_position = self::hasGetDebugTypeCheck($conditional);
if ($get_debug_type_position) { if ($get_debug_type_position) {
if ($get_debug_type_position === self::ASSIGNMENT_TO_RIGHT) { if ($get_debug_type_position === self::ASSIGNMENT_TO_RIGHT) {
$whichclass_expr = $conditional->left; $whichclass_expr = $conditional->left;
@ -1759,7 +1771,6 @@ class AssertionFinder
} }
$getclass_position = self::hasGetClassCheck($conditional, $source); $getclass_position = self::hasGetClassCheck($conditional, $source);
$typed_value_position = self::hasTypedValueComparison($conditional, $source);
if ($getclass_position) { if ($getclass_position) {
if ($getclass_position === self::ASSIGNMENT_TO_RIGHT) { if ($getclass_position === self::ASSIGNMENT_TO_RIGHT) {
@ -1832,6 +1843,8 @@ class AssertionFinder
return $if_types ? [$if_types] : []; return $if_types ? [$if_types] : [];
} }
$typed_value_position = self::hasTypedValueComparison($conditional, $source);
if ($typed_value_position) { if ($typed_value_position) {
if ($typed_value_position === self::ASSIGNMENT_TO_RIGHT) { if ($typed_value_position === self::ASSIGNMENT_TO_RIGHT) {
$var_name = ExpressionIdentifier::getArrayVarId( $var_name = ExpressionIdentifier::getArrayVarId(