Skip to content

Generic.WhiteSpace.ScopeIndent false positive for arrow functions inside arrays #3362

@BinaryKitten

Description

@BinaryKitten

Describe the bug
A clear and concise description of what the bug is.

Code sample

<?php

$overrides = [
    'abcd1234' => [ // name
        'title' => function ($product) {
            return trim(substr($product['title'], 0, 100));
        }
    ],
    'abcd1255' => [ //company - Remove '2019/19' from the beginning of their title
        'title' => fn ($product) => trim(preg_replace('/^[0-9\/]{4,7}/', '', $product['title']))
    ],
    'abcd9982' => [ // another company
        'type' => 'Product Delivery', // Product Delivery
    ]
];

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs --standard=Generic --sniffs=Generic.WhiteSpace.ScopeIndent test.php
  3. See error message displayed
---------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------
 14 | ERROR | [x] Line indented incorrectly; expected at least 8 spaces, found 4
---------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------

Expected behavior
no error - spaces = 4 should be correct?

Versions (please complete the following information):

  • OS: Ubunutu 18.04
  • PHP: 7.4.16
  • PHPCS: 3.6

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