earlyReturn confused by elseif
Bug Report
| Subject | Details |
|---|---|
| Rector version | v1.2.4 |
The earlyReturn dropped a whole code branch.
INPUT:
protected function checkACL($area)
{
if (in_array(strtolower($area), ['false', '0', 'no', '403'])) {
return false;
}
if (in_array(strtolower($area), ['true', '1', 'yes'])) {
return true;
} elseif (empty($area)) {
return true;
} else {
// ... A big block of code
}
return false;
}
OUTPUT:
protected function checkACL($area)
{
if (in_array(strtolower($area), ['false', '0', 'no', '403'])) {
return false;
}
if (in_array(strtolower($area), ['true', '1', 'yes'])) {
return true;
}
return empty($area);
}
Minimal PHP Code Causing Issue
php v8.3.6
Expected Behaviour
If the elseif can be refactored, the rector must do so to keep the functionality as precise as the original code. In this case, it seems that it assumed to be equivalent to return empty($area);.
If the elseif is too complex, rector must skip it.
Thank you for your report!
We'll need an isolated failing demo link from: http://getrector.com/demo, that way we can reproduce the bug.
I tried to create the isolated test case, but it didn't produce the same result.
We're unable to provide fix without failing reproducer we can add to our test suite.
closing as answered and needs reproducible code/config to make a fix.