Skip to content

InlineControlStructure CBF issue while adding braces to an if thats returning a nested function #1590

@hchow77

Description

@hchow77

Not very happy with how this code came into being, but does seem to have resulted in a pretty bad CBF fix while using Generic.ControlStructures.InlineControlStructure.NotAllowed. Can't really put it into words because it's so hairy, but here's what it starts out as:

class Clazz {
    public function foo() {
        $num = 0;
        switch ($num) {
            case 0:
                if (1 > $num)
                    return bar(
                        baz(
                            "foobarbaz"
                        )
                    );
                break;

            default:
                return bar("foobarbaz");
        }
    }
}

After running I get:

class Clazz {
    public function foo() {
        $num = 0;
        switch ($num) {
            case 0:
                if (1 > $num) {
                    return;
                } bar(
                        baz(
                            "foobarbaz"
                        )
                    );
                break;

            default:
                return bar("foobarbaz");
        }
    }
}

Note, it's no longer returning the result of bar, which seems pretty bad. Given the code was awful to begin with, and noticed that making fine adjustments that would have made this code better makes it work right, but I'm surprised that CBF is sneaking in this semicolon in this case in particular.

Appreciate the consideration!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions