Skip to content

AlignMultilineParametersFixer: how to handle multiline type declaration? #7

@erickskrauch

Description

@erickskrauch

Here is a bug:

function test(
    string $string = "string",
    int |
    (
        JsonSerializable
        &
        Stringable
    )|
    null $int = 0
) {}
}

This is a weird but the correct way to write a type. Right now the AlignMultilineParametersFixer will calculate the length of the type with all those tabulation spaces and put the names of the parameters really far away to the left.

The PHP-CS-Fixer's TypesSpacesFixer doesn't fix such multiline type declarations and I didn't find any other fixer suited for this task, so it seems that this code was left on the user's side.

It seems that I can calculate the length of each line and take the longest line as the type length:

function test(
    string               $string = "string",
    int |
    (
        JsonSerializable
        &
        Stringable
    )|
    null                 $int = 0
) {}
}

But I'm not sure about this solution at this moment. So I'll leave this issue open until somebody also occurs this in a real code and gives me some feedback about expected behavior.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions