[CodingStyle][EarlyReturn] Fix infinite if else on BinarySwitchToIfElseRector+RemoveAlwaysElseRector#5057
Conversation
…seRector+RemoveAlwaysElseRector
|
@jlherren this should fix rectorphp/rector#8220, the remove always else need on second run :) |
|
All checks have passed 🎉 @TomasVotruba I am merging it ;) |
|
Thanks 👍 I still think the switch to if/else is kind of pointless with match. I recall it was my idea to add this rule to avoid switched back in PHP 7.4 :) but now match seem like much better logical choice, that this rule would skip. |
|
switch to match is part of upgrade, while that can cause a different logic, as need default value: this code doesn't have default value to compare so mostly use if else. |
|
Without default value, it will cause BinarySwitchToIfElse is to make if elseif works and the transformation keep working as expected. |
|
Else is the default here, so it can be upgraded to switch (mt_rand()) {
case 1:
return 10;
case 2:
return 20;
}
return 30;↓ return match(mt_rand()) {
1 => 10,
2 => 20,
default => 30,
};The |
|
I think that depends, if no last return, this rule still make sense, see https://getrector.com/demo/0412d7c9-b99a-4299-a945-7f735cbc9fd9 |
Indeed, that's why PHPStan and developer should handle these. In |
|
which change to if elseif is more valid. |
Fixes rectorphp/rector#8220