Skip to content

PSR2 SwitchDeclaration sniff doesn't detect, or correctly fix, case body on same line as statement #621

@oujesky

Description

@oujesky

When running PSR2.ControlStructures.SwitchDeclaration sniff fix on following code:

switch ($foo) {
    case 1: $bar = 1; break;
    case 2: $bar = 2; break;
    case 21:
    case 3: return 3;
    default: $bar = 0;
}

the expected result should be

switch ($foo) {
    case 1:
        $bar = 1;
        break;
    case 2:
        $bar = 2;
        break;
    case 21:
    case 3:
        return 3;
    default:
        $bar = 0;
}

but the actual result is messed up:

switch ($foo) {
    case 1: $barbreak;
    case 2: $barbreak;
    case 21:
    case 3return 3;
    default: $bar = 0;
}

It seems the last few tokens before case end (be it break or return) are just removed.

I can supply this code to SwitchDeclarationUnitTest.inc and SwitchDeclarationUnitTest.inc.fixed respectively, however I am not sure I can come with actual PR to fix this.

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