-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Generic.Formatting.MultipleStatementAlignment false positive for match()
#3862
Comments
Seeing the error and the code example I think PHPCS is making the correct suggestion (I get exactly the same error). From the docs (
In the example This was checked just now using the main branch (on commit b6264f9). |
That's actually not true. They do belong to the same block of assignments, multi-line argument or not. While opinions may vary whether that is correct, the sniff should at least be consistent and for consistency, the above should be seen as a bug. Expanded code sample showing other multiline assignments<?php declare(strict_types = 1);
namespace Bug;
class A {
public function bug(bool $b): void {
$a = match ($b) {
true => 1,
default => false,
};
$var = 123;
$a = match ($b) {
true => 1,
default => false,
};
$a = function ($b) {
return $b;
};
$var = 123;
$a = function ($b) {
return $b;
};
$a = 'multi-'
. 'line';
$var = 123;
$a = 'multi-'
. 'line';
echo $a.$var;
}
} Result:
In other words: the first match on line 7 is treated inconsistently compared to other multi-line assignments, which all expect alignment. |
Describe the bug
Generic.Formatting.MultipleStatementAlignment
doesn't work correctly withmatch()
.Code sample
Custom ruleset
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php ...
Expected behavior
No error.
Versions (please complete the following information)
Please confirm:
master
branch of PHP_CodeSniffer.The text was updated successfully, but these errors were encountered: