-
-
Notifications
You must be signed in to change notification settings - Fork 737
Closed
rectorphp/rector-src
#6867Labels
Description
Bug Report
| Subject | Details |
|---|---|
| Rector version | last dev-main |
| Installed as | composer dependency |
Minimal PHP Code Causing Issue
See https://getrector.com/demo/d4f318da-16f2-47a7-b884-dd2bd07bd430
<?php
final class DemoFile {
public function preparedValueForeach(): bool {
$test = true;
foreach([true, false] as $item) {
if(!$item) $test = false;
}
if(rand(0, 1)) $test = false;
return $test;
}
}Responsible rules
PreparedValueToEarlyReturnRector
Expected Behavior
Rector should return the result of $test from the foreach() in the last line
Actual Behavior
Rector returns fixed true in the last line and removes the initial $test = true; in the first line, ignoring the state change from the foreach() which breaks code logic.
I'm not sure which result is more fitting, so I'm making 2 pull requests for tests.