rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.72k stars 687 forks source link

Incorrect behavior of ExplicitBoolCompareRector - double variable assignment in condition #8741

Closed etshy closed 3 weeks ago

etshy commented 3 months ago

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

Expected Behavior

Not doubling the variable assignment. Or make the variable assignment before the condition and then using the variable.

samsonasik commented 3 months ago

we are aware of it, just not a priority right now https://github.com/rectorphp/rector/issues/8663#issuecomment-2144728710

samsonasik commented 3 weeks ago

Re-open, assign inside condition seems needs special check, also the ExplicitBoolCompareRector seems not using ExactCompareFactory