From a82a9558d2e8e3964c21d2ed5b8c526754f4d9a0 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Tue, 10 Nov 2020 12:50:17 -0500 Subject: [PATCH] Experiment with refactor --- .../Statements/Expression/AssertionFinder.php | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 2dfb1fdb1..ff17fdd07 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -577,13 +577,6 @@ class AssertionFinder $if_types = []; $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 === self::ASSIGNMENT_TO_RIGHT) { @@ -657,6 +650,8 @@ class AssertionFinder return $if_types ? [$if_types] : []; } + $true_position = self::hasTrueVariable($conditional); + if ($true_position) { if ($true_position === self::ASSIGNMENT_TO_RIGHT) { $base_conditional = $conditional->left; @@ -775,6 +770,8 @@ class AssertionFinder return $if_types; } + $false_position = self::hasFalseVariable($conditional); + if ($false_position) { if ($false_position === self::ASSIGNMENT_TO_RIGHT) { $base_conditional = $conditional->left; @@ -884,6 +881,8 @@ class AssertionFinder return $if_types; } + $empty_array_position = self::hasEmptyArrayVariable($conditional); + if ($empty_array_position !== null) { if ($empty_array_position === self::ASSIGNMENT_TO_RIGHT) { $base_conditional = $conditional->left; @@ -948,6 +947,8 @@ class AssertionFinder return $if_types ? [$if_types] : []; } + $gettype_position = self::hasGetTypeCheck($conditional); + if ($gettype_position) { if ($gettype_position === self::ASSIGNMENT_TO_RIGHT) { $string_expr = $conditional->left; @@ -987,6 +988,8 @@ class AssertionFinder return $if_types ? [$if_types] : []; } + $get_debug_type_position = self::hasGetDebugTypeCheck($conditional); + if ($get_debug_type_position) { if ($get_debug_type_position === self::ASSIGNMENT_TO_RIGHT) { $whichclass_expr = $conditional->left; @@ -1033,6 +1036,9 @@ class AssertionFinder return $if_types ? [$if_types] : []; } + $min_count = null; + $count_equality_position = self::hasNonEmptyCountEqualityCheck($conditional, $min_count); + if ($count_equality_position) { if ($count_equality_position === self::ASSIGNMENT_TO_RIGHT) { $count_expr = $conditional->left; @@ -1268,13 +1274,6 @@ class AssertionFinder $if_types = []; $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 === self::ASSIGNMENT_TO_RIGHT) { @@ -1349,6 +1348,8 @@ class AssertionFinder return $if_types ? [$if_types] : []; } + $false_position = self::hasFalseVariable($conditional); + if ($false_position) { if ($false_position === self::ASSIGNMENT_TO_RIGHT) { $base_conditional = $conditional->left; @@ -1450,6 +1451,8 @@ class AssertionFinder return $if_types ? [$if_types] : []; } + $true_position = self::hasTrueVariable($conditional); + if ($true_position) { if ($true_position === self::ASSIGNMENT_TO_RIGHT) { $base_conditional = $conditional->left; @@ -1563,6 +1566,9 @@ class AssertionFinder return $if_types; } + $count = null; + $count_inequality_position = self::hasNotCountEqualityCheck($conditional, $count); + if ($count_inequality_position) { if ($count_inequality_position === self::ASSIGNMENT_TO_RIGHT) { $count_expr = $conditional->left; @@ -1590,6 +1596,8 @@ class AssertionFinder return $if_types ? [$if_types] : []; } + $empty_array_position = self::hasEmptyArrayVariable($conditional); + if ($empty_array_position !== null) { if ($empty_array_position === self::ASSIGNMENT_TO_RIGHT) { $base_conditional = $conditional->left; @@ -1659,6 +1667,8 @@ class AssertionFinder return $if_types ? [$if_types] : []; } + $gettype_position = self::hasGetTypeCheck($conditional); + if ($gettype_position) { if ($gettype_position === self::ASSIGNMENT_TO_RIGHT) { $whichclass_expr = $conditional->left; @@ -1708,6 +1718,8 @@ class AssertionFinder return $if_types ? [$if_types] : []; } + $get_debug_type_position = self::hasGetDebugTypeCheck($conditional); + if ($get_debug_type_position) { if ($get_debug_type_position === self::ASSIGNMENT_TO_RIGHT) { $whichclass_expr = $conditional->left; @@ -1759,7 +1771,6 @@ class AssertionFinder } $getclass_position = self::hasGetClassCheck($conditional, $source); - $typed_value_position = self::hasTypedValueComparison($conditional, $source); if ($getclass_position) { if ($getclass_position === self::ASSIGNMENT_TO_RIGHT) { @@ -1832,6 +1843,8 @@ class AssertionFinder return $if_types ? [$if_types] : []; } + $typed_value_position = self::hasTypedValueComparison($conditional, $source); + if ($typed_value_position) { if ($typed_value_position === self::ASSIGNMENT_TO_RIGHT) { $var_name = ExpressionIdentifier::getArrayVarId(