Skip to content

Invalid warning in multiple assignments alignment with closure or anon class #1870

Closed
@Dacaspex

Description

@Dacaspex

The following example is marked as invalid by phpcs

1 $foobarbaz = array_map(
2    function ($n) {
3         return $n * $n;
4     },
5     [1, 2, 3]
6 );
7 $foo       = 5;

This causes the following warning on line 7:

Generic.Formatting.MultipleStatementAlignment.IncorrectWarning

Basically, the $foo is considered to be a new assignment block. The reason for this, I think, is the semicolon in the function closure on line 3. Phpcs thinks the assignment block has ended because the semicolon is in a different context.

The reason I think this should not happen is because PHPStorm automatically aligns the equals sign like the example given above. This is because of the code style option Assignment statement -> Align consecutive assignments in PHPStorm.

Hence my question whether this can be added/fixed in phpcs?

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