Skip to content

Incorrect behavior of RemoveUnreachableStatementRector #9117

@noother

Description

@noother

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/3a082b48-0b5f-4662-b85c-c50ab158a040

<?php

final class switchBreakNotUnreachable {
    public function run(): bool {
        switch('test') {
            case 'test':
                if(rand(0, 1)) break;

                return false;
            default:
                return false;
        }

        return true;
    }
}

Responsible rules

  • RemoveUnreachableStatementRector

Expected Behavior

Rector shouldn't touch the code here

Actual Behavior

Rector removes the return true; at the end, even though it's not unreachable, breaking code logic and syntax.

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