Describe the bug
Generic.WhiteSpace.ScopeIndent reports a false positive for an array item following a multi-line function call whose final argument is an arrow function ending with a method call.
The problem occurs in a PHP template when an inline short echo appears earlier in a nested HTML element.
Code sample
<?php
?>
<div>
<div>
<span><?= $title ?></span>
</div>
<?= render(
[
'data' => map(
[],
static fn($item) => $item->getValue()
),
'options' => [],
]
) ?>
</div>
To reproduce
phpcs --standard=PSR12 -s test.php
Actual behavior
FOUND 1 ERROR AFFECTING 1 LINE
15 | ERROR | [x] Line indented incorrectly; expected at least 14 spaces,
| | found 12
| | (Generic.WhiteSpace.ScopeIndent.Incorrect)
The reported array key is correctly indented with 12 spaces.
PHPCBF changes it to 14 spaces:
This satisfies ScopeIndent, but conflicts with Generic.Arrays.ArrayIndent:
Array key not indented correctly; expected 12 spaces but found 14
(Generic.Arrays.ArrayIndent.KeyIncorrect)
Expected behavior
No error should be reported. The options key is at the same array level as data and should use the same indentation.
Additional observations
The false positive disappears if the arrow function method call:
static fn($item) => $item->getValue()
is changed to property access:
static fn($item) => $item->value
It also disappears if the preceding nested inline short echo is removed.
This may be related to #968, but the issue is still reproducible in PHP_CodeSniffer 4.0.1.
Versions
|
|
| Operating System |
Linux |
| PHP version |
8.5.7 |
| PHP_CodeSniffer version |
4.0.1 |
| Standard |
PSR12 |
| Install type |
Composer |
Describe the bug
Generic.WhiteSpace.ScopeIndentreports a false positive for an array item following a multi-line function call whose final argument is an arrow function ending with a method call.The problem occurs in a PHP template when an inline short
echoappears earlier in a nested HTML element.Code sample
To reproduce
Actual behavior
The reported array key is correctly indented with 12 spaces.
PHPCBF changes it to 14 spaces:
'options' => [],This satisfies
ScopeIndent, but conflicts withGeneric.Arrays.ArrayIndent:Expected behavior
No error should be reported. The
optionskey is at the same array level asdataand should use the same indentation.Additional observations
The false positive disappears if the arrow function method call:
is changed to property access:
It also disappears if the preceding nested inline short echo is removed.
This may be related to #968, but the issue is still reproducible in PHP_CodeSniffer 4.0.1.
Versions