rectorphp / rector

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

Incorrect behavior of RemoveAlwaysTrueIfConditionRector #8583

Closed georgec-floyt closed 5 months ago

georgec-floyt commented 5 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/8d8a04b4-7402-4bb6-8126-f484e690111c

<?php

final class ChildClass extends VendorClass
{
    private bool $executed;

    public function run(): void
    {
        $this->executed = false;

        parent::run();

        if (!$this->executed) {
            echo 'not run';
        }
    }

    protected function execute(): void
    {
        $this->executed = true;

        parent::run();
    }
}

class VendorClass
{
    public function run()
    {
        $this->execute();
    }
    protected function execute()
    {
    }
}

(new ChildClass)->run();

Responsible rules

Expected Behavior

Rector should skip it. Adding the return value of : void in the vendor run method fixes the issue.

samsonasik commented 5 months ago

it seems when : void not defined, it become ConstantBooleanType with always true value, while when : void defined, it become BooleanType