Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
etshy opened this issue Jul 16, 2024 · 2 comments · Fixed by rectorphp/rector-src#6388 or rectorphp/rector-src#6389

Comments

@etshy
Copy link

etshy commented Jul 16, 2024

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.

@etshy etshy added the bug label Jul 16, 2024
@samsonasik
Copy link
Member

we are aware of it, just not a priority right now #8663 (comment)

@samsonasik
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants