Skip to content

Generic/InlineControlStructures: sniff does not allow while without body #2822

@jrfnl

Description

@jrfnl

A while control structure without body is perfectly valid PHP but gets flagged by the Generic.ControlStructures.InlineControlStructures sniff.

$i = 10;
while ($i > 0 && --$i);

// $i is now 0

See: https://3v4l.org/RXNqL

As far as I can see, the sniff is intended to find inline control structures with a body, but without braces and fix those. An inline control structure without a body should be outside the scope of this sniff.

I've got a fix ready for this, but found that a number of existing unit test would start failing (line 42, 43, 226, 228 and 230).

@gsherwood With that in mind, I'd like second opinion on how the sniff should handle while structures without body.

As an alternative to the fix I've got prepared, I could create a fix which would maintain the existing behaviour, but would give while structures without a body a different error code.

Opinions ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions