rector
rector copied to clipboard
RemoveAlwaysTrueIfConditionRector with array_push is buggy
trafficstars
Bug Report
| Subject | Details |
|---|---|
| Rector version | 1.2.5 |
RemoveAlwaysTrueIfConditionRector removes a correct if statement. Code is quite ugly. It seems the problem is with:
- array_push .... with "$outerList[$id][] = [];" insetad of "array_push($outerList[$id], []);" it works
- an array with at least 2 foreach iterations are needed => with "$idList = [1];" it works
private function demo(): void
{
$outerList = [];
$idList = [1, 2];
foreach ($idList as $id) {
$outerList[$id] = [];
array_push($outerList[$id], []);
}
$resultSet = [];
foreach ($outerList as $key => $outerElement) {
$result = false;
foreach ($outerElement as $innerElement) {
$result = true;
}
if (!$result) {
array_push($resultSet, $key);
}
}
}
rector remove the if statement:
- if (!$result) {
- array_push($resultSet, $key);
- }
+ array_push($resultSet, $key);
Expected Behaviour
Rule should not be executed/change code