Skip to content

RemoveDoubleAssignRector: removes values inside switch statement #1340

@msvrtan

Description

@msvrtan

In switch statements, it will remove assignments without removing break blocks which produces logical errors in code:

(Just to be clear I'm not suggesting that breaks should be removed, IMO it should skip this cases)

class Example{

    public function action(...)
    {
        // work done

        switch ($var) {
            case 1:
                $a = 14;
                break;
            case 2:
                $a = 55;
                break;
            case 3:
                $a = 777;
                break;
            case 4:
                $a = 777;
                break;
            case 5:
                $a = 777;
                break;
            default:
                $points = 0;
        }
        // work done
    }
}

will be converted to

class Example{

    public function action(...)
    {
        // work done

        switch ($var) {
            case 1:
                $a = 14;
                break;
            case 2:
                $a = 55;
                break;
            case 3:
                $a = 777;
                break;
            case 4:
                break;
            case 5:
                break;
            default:
                $points = 0;
        }
        // work done
    }
}

Version v0.4.11

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