Skip to content

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

Closed
@TimWolla

Description

@TimWolla

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

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