Skip to content

Wrongly assumed indentation with match and arrays #3287

@iquito

Description

@iquito

Using PSR-12 with current dev-master the PHP8 match clause and arrays have a "wrong" indentation interaction:

class TestClass
{
    public function dada(string $type): array
    {
        return match ($type) {
            'referrers' => [
                'referrersNumber' => 'DESC',
                'visitorsNumber' => 'DESC',
                'viewsNumber' => 'DESC',
            ],
            'orders' => [
                'ordersNumber' => 'DESC',
                'visitorsNumber' => 'DESC',
                'viewsNumber' => 'DESC',
                'referrersNumber' => 'DESC',
            ],
            default => [
                'visitorsNumber' => 'DESC',
                'viewsNumber' => 'DESC',
                'referrersNumber' => 'DESC',
            ],
        };
    }
}

Reports the following errors:

 18 | ERROR | [x] Line indented incorrectly; expected at least 16 spaces, found 12
 19 | ERROR | [x] Line indented incorrectly; expected at least 16 spaces, found 12
 23 | ERROR | [x] Line indented incorrectly; expected at least 16 spaces, found 12

The lines reported are the one before the default clause, the line with the default clause, and the ending array of the default clause. There errors always seem to start at the end of the second array, with or without a default clause. When using other types instead of arrays no errors occur.

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