Skip to content

Incorrect behavior of RemoveAlwaysTrueIfConditionRector #8583

@ghost

Description

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

  • RemoveAlwaysTrueIfConditionRector

Expected Behavior

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions