Open
Description
Describe the bug
Indentation is reported as off when it's not (false positive).
"Correcting" it produces an indentation-related error from another sniff (a valid one).
AFAICT the issue is triggered by the arrow function contained in the function call.
Code sample
<?php
namespace My;
class Example
{
public static function test(): string
{
return json_encode(
array_filter(
[
'foo' => 42,
'bar' => null,
],
static fn(mixed $value) => $value !== null
),
JSON_THROW_ON_ERROR
);
}
}
Code example variant
<?php
namespace My;
class Example
{
public static function test(): string
{
$value = array_filter(
[
'foo' => 42,
'bar' => null,
],
static fn(mixed $value) => $value !== null
);
return json_encode($value, JSON_THROW_ON_ERROR);
}
}
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php
with the code sample above - Run
phpcs test.php --standard=PSR12
- See error message displayed
FILE: /path/to/test.php
-----------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------
17 | ERROR | [x] Line indented incorrectly; expected at least 16 spaces, found 12
-----------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------
Expected behavior
No errors/warnings
Versions (please complete the following information)
Operating System | any (tried with MacOS 15.3.2) |
PHP version | any recent one (tried with 8.3.19) |
PHP_CodeSniffer version | 3.12.2, master |
Standard | PSR12 |
Install type | Composer |
Please confirm
- I have searched the issue list and am not opening a duplicate issue.
- I have read the Contribution Guidelines and this is not a support question.
- I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- I have verified the issue still exists in the
master
branch of PHP_CodeSniffer.