Skip to content

Generic.WhiteSpace.ScopeIndent reports incorrect errors when indenting double arrows in short arrays #1465

Closed
@panvid

Description

@panvid

I found a very strange behaviour with line endings in an array of arrays. Lets look to the following code.

Correct code

<?php
declare(strict_types=1);
return [
    'veryLongKeySoIWantToMakeALineBreak' => 'veryLonValueSoIWantToMakeALineBreak',

    'someOtherKey' => [
        'someValue'
    ],

    'arrayWithArraysInThere' => [
        ['Value1', 'Value1']
    ],
];

There is no error, no problem, no warning with CodeSniffer.

After a line break it also looks good without any problem

<?php
declare(strict_types=1);
return [
    'veryLongKeySoIWantToMakeALineBreak'
    => 'veryLonValueSoIWantToMakeALineBreak',

    'someOtherKey' => [
        'someValue'
    ],

    'arrayWithArraysInThere' => [
        ['Value1', 'Value1']
    ],
];

Lets intend after the line break

Because of a not good looking intendation of first key/value assignment I move the assignment with 4 spaces

<?php
declare(strict_types=1);
return [
    'veryLongKeySoIWantToMakeALineBreak'
        => 'veryLonValueSoIWantToMakeALineBreak',

    'someOtherKey' => [
        'someValue'
    ],

    'arrayWithArraysInThere' => [
        ['Value1', 'Value1']
    ],
];

No there is the first warning: phpcs: Line intended incorrectly; expected at least 8 spaces, found 4. But I get this warning on the last key/value assignment (on arrayWithArrayInThere). Why I get this?

"Solve" this problem with the third assignment

This warning can be solved, not only be intending the first assignment but changing the third key/value pair.

<?php
declare(strict_types=1);
return [
    'veryLongKeySoIWantToMakeALineBreak'
        => 'veryLonValueSoIWantToMakeALineBreak',

    'someOtherKey' => ['someValue'],

    'arrayWithArraysInThere' => [
        ['Value1', 'Value1']
    ],
];

The intendation does not change, only the postion of the value of the third key/value pair. Why? Oo

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