Skip to content

SlevomatCodingStandard.ControlStructures.EarlyExit causes "if" without curly braces is not supported #1506

@momala454

Description

@momala454

The rule SlevomatCodingStandard.ControlStructures.EarlyExit will cause the following error at line 1 (but there is nothing on line 1), and there shouldn't be any error, the code is valid and doesn't contains any if without a curly brace

FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------
 1 | ERROR | An error occurred during processing; checking has been aborted. The error message was: "if" without curly braces is not supported.
------------------------------------------------------------------------------------------------------------------------------------------------

To reproduce:

function testBugCurly(): void
{
    foreach ([1,2] as $step) {
        if (1 !== 1) {
            continue;
        }

        if (1 !== null) {
            if (!match (1) {
                default => 1,
            }) {
            }
        }
    }
}

Strangely, adding anything (even a comment) on the last line inside foreach avoid the error. Like this :

function testBugCurly(): void
{
    foreach ([1,2] as $step) {
        if (1 !== 1) {
            continue;
        }

        if (1 !== null) {
            if (!match (1) {
                default => 1,
            }) {
            }
        }
        // hello
    }
}

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