Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrongly assumed indentation with match and arrays #3287

Closed
iquito opened this issue Mar 31, 2021 · 1 comment
Closed

Wrongly assumed indentation with match and arrays #3287

iquito opened this issue Mar 31, 2021 · 1 comment
Milestone

Comments

@iquito
Copy link

iquito commented Mar 31, 2021

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.

@iquito iquito changed the title Wrongly assumed match indentation with arrays Wrongly assumed indentation with match and arrays Mar 31, 2021
gsherwood added a commit that referenced this issue Apr 5, 2021
Match checking in findStartOfStatement needed to skip over short arrays and function calls etc, so now using findEndOfStatement for that. That exposed a bug in findEndOfStatement when checking a match arrow directly, which is now also fixed.
gsherwood added a commit that referenced this issue Apr 5, 2021
Match checking in findStartOfStatement needed to skip over short arrays and function calls etc, so now using findEndOfStatement for that. That exposed a bug in findEndOfStatement when checking a match arrow directly, which is now also fixed.
@gsherwood
Copy link
Member

Thanks a lot for testing master and reporting this. This was caused by match expression support in findStartofStatement and findEndOfStatement being incorrect. Once fixing those, the sniff reports indentation correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants