rector
rector copied to clipboard
Incorrect behavior of ExplicitBoolCompareRector - double variable assignment in condition
Bug Report
| Subject | Details |
|---|---|
| Rector version | last dev-main |
| Installed as | composer dependency |
Minimal PHP Code Causing Issue
See https://getrector.com/demo/df4a4011-49f2-4fd2-96e7-a1627ebb4eaa
<?php
declare(strict_types=1);
final class DemoFile
{
public function run(): int|string
{
if ($base64 = base64_encode('')) {
return 5;
}
return '10';
}
}
Responsible rules
-
ExplicitBoolCompareRector
Expected Behavior
Not doubling the variable assignment. Or make the variable assignment before the condition and then using the variable.
we are aware of it, just not a priority right now https://github.com/rectorphp/rector/issues/8663#issuecomment-2144728710
Re-open, assign inside condition seems needs special check, also the ExplicitBoolCompareRector seems not using ExactCompareFactory