You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Issue 411] - Fix and refactor ThrowIfRector rule (#415)
* Refactor the rule ThrowIfRector class.
* Adjust the rule logic to skip cases with unsafe nodes.
* Rector fixes.
* Duster fixes.
* Rename fixture class.
* Renaming.
* Organize transformation safety validation under a single method.
* Rewrite the logic for safety-validation of variable accesses, don't just skip for any variable that was assigned in the if-condition, but only that could be not initialized because of the short-circuit issue.
* rector.
* duster.
$this->traverseNodesWithCallable($throwExpr, function (Node$node) use ($conditionVariables, &$returnValue): ?int {
121
-
if ($nodeinstanceof Variable && in_array($this->getName($node), $conditionVariables, true)) {
122
-
$returnValue = true;
124
+
return$shouldTransform;
125
+
}
123
126
124
-
return NodeVisitor::STOP_TRAVERSAL;
125
-
}
127
+
/**
128
+
* Not safe to transform when throw expression contains variables that are assigned in the if-condition because of the short-circuit logical operators issue.
129
+
* This method checks if the variable was assigned on the right side of a short-circuit logical operator (conjunction and disjunction).
130
+
* Note: The check is a little too strict, because such a variable may be initialized before the if-statement, and in such case it doesn't matter if it was assigned somewhere in the condition.
0 commit comments