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

Incorrect ScopeIndent.IncorrectExact report for match inside array literal #3672

Closed
TimWolla opened this issue Sep 21, 2022 · 2 comments
Closed

Comments

@TimWolla
Copy link

Describe the bug

phpcs in PSR12 mode reports that a line is indented incorrectly when it is correctly indented according to my understanding.

Code sample

<?php

namespace foo;

class Foo
{
    public static function foo(array $foo): array
    {
        return \array_map(static function ($foo) {
            return [
                match ($foo) {
                    0 => 1,
                    1 => 0,
                },
                $foo,
            ];
        }, $foo);
    }
}

Custom ruleset

--standard=PSR12

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs --standard=PSR12 -s test.php
  3. See error message displayed
FILE: /pwd/test.php
--------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
--------------------------------------------------------------------------------------------------------------------------
 11 | ERROR | [x] Line indented incorrectly; expected 12 spaces, found 16
    |       |     (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
 14 | ERROR | [x] Line indented incorrectly; expected 12 spaces, found 16
    |       |     (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
--------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------

Time: 73ms; Memory: 8MB

When reformatting with phpcbf the file will look like this afterwards:

<?php

namespace foo;

class Foo
{
    public static function foo(array $foo): array
    {
        return \array_map(static function ($foo) {
            return [
            match ($foo) {
                0 => 1,
                1 => 0,
            },
                $foo,
            ];
        }, $foo);
    }
}

Expected behavior

I did not expect any errors in the given file.

I expected phpcbf not to change the file.

Versions (please complete the following information):

  • OS: Ubuntu 20.04, Docker.
  • PHP: 8.1
  • PHPCS: PHP_CodeSniffer version 3.7.1 (stable) by Squiz (http://www.squiz.net)
  • Standard: PSR12

Additional context

n/a

@gsherwood
Copy link
Member

gsherwood commented Sep 22, 2022

Looks to be something wrong going on here; possibly a conflict between ignoring exact indents and fixed indents for control structures.

Smallest sample code to replicate:

foo(function ($foo) {
    return [
        match ($foo) {
        }
    ];
});

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Sep 22, 2022
@gsherwood gsherwood added this to the 3.7.2 milestone Sep 22, 2022
gsherwood added a commit that referenced this issue Sep 26, 2022
gsherwood added a commit that referenced this issue Sep 26, 2022
@gsherwood
Copy link
Member

I've pushed a fix for this issue, which will be in the 3.7.2 release. Thanks for the bug report.

PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

No branches or pull requests

2 participants