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
I have two issues with the issue PhanPluginRedundantAssignmentInLoop.
The first problem is that PhanPluginRedundantAssignmentInLoop is issued for the wrong line number in the file, which makes it harder to find the mention assignment.
The second problem is, that for the example code the issue should not be emitted, because the variable is changed in a way that the assignment is needed.
Issue: ..php:33 PhanPluginRedundantAssignmentInLoop Assigning 0 to variable $consecutiveErrors which already has that value
Example
<?php
class Task {
public function isComplete():bool {
return (bool)mt_rand( 0, 1 );
}
public function getStatus(): self {
if( mt_rand( 0 , 1 ) ) {
return new Task();
}
throw new LogicException();
}
}
class TestClass {
private const MAX_CONSECUTIVE_ERRORS = 3;
private function task( Task $task ) {
$consecutiveErrors = 0;
while ( !$task->isComplete() ) {
try {
$status = $task->getStatus();
} catch ( \Exception $e ) {
if ( ++$consecutiveErrors > self::MAX_CONSECUTIVE_ERRORS ) {
$this->fatalError();
}
continue;
}
$consecutiveErrors = 0; # <!-- Correct context
echo "something";
if ( !$status->isComplete() ) { # <!-- PhanPluginRedundantAssignmentInLoop Assigning 0 to variable $consecutiveErrors which already has that value
sleep( 10 );
}
}
}
private function fatalError(): never {
throw new LogicException();
}
}
The example is from a long running maintenance script which runs and retry the task as long it is not failing 3 times in serie.
The text was updated successfully, but these errors were encountered:
I am using phan 5.2.0
I have two issues with the issue
PhanPluginRedundantAssignmentInLoop
.PhanPluginRedundantAssignmentInLoop
is issued for the wrong line number in the file, which makes it harder to find the mention assignment.Issue:
..php:33 PhanPluginRedundantAssignmentInLoop Assigning 0 to variable $consecutiveErrors which already has that value
Example
The example is from a long running maintenance script which runs and retry the task as long it is not failing 3 times in serie.
The text was updated successfully, but these errors were encountered: