-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PSR2 standard can't auto fix multi-line function call inside a string concat statement #2506
Comments
This is a fixer conflict between the The problem (in both cases) is caused by the function call being concatenated onto a text string spanning multiple lines. Looking at the code of the first example, IMO the correct fix would be to indent the code like below where the indent of the function call parameters is based on the indent of the Based on an initial check, it looks like both sniffs get it wrong. The <?php
class C
{
public function m()
{
$t = '
' . (empty(true) ? '
' . f(
'1',
'2',
'3',
'4'
) . '
' : '');
}
} |
Does this mean that I have to manually resolve such conflicts? |
@stdex No, sorry, I wasn't clear. My post was just to add additional information to the issue in hopes that a solution can be found. |
…ll inside a string concat statement
I've added a fix for the first case. The PSR2 standard will now fix this code: <?php
class C
{
public function m()
{
$t = '
' . (empty(true) ? '
' . f(
'1',
'2',
'3',
'4'
) . '
' : '');
}
} So that it looks like this: <?php
class C
{
public function m()
{
$t = '
' . (empty(true) ? '
' . f(
'1',
'2',
'3',
'4'
) . '
' : '');
}
} The second case is something slightly different and needs to be fixed separately. |
Slightly different fix for the second code snippet reported there. Uses startOfStatement instead of line unless it detects method chaining.
I've added another fix into the same sniff for the second case. The PSR2 standard will now fix this code: <?php
class C
{
public function m()
{
$a = [];
$t =
"SELECT * FROM t
WHERE f IN(" . implode(
",",
$a
) . ")";
}
} So that it looks like this: <?php
class C
{
public function m()
{
$a = [];
$t =
"SELECT * FROM t
WHERE f IN(" . implode(
",",
$a
) . ")";
}
} Thanks for the bug report. |
Hello.
PHP_CodeSniffer version 3.4.2 (stable)
Call:
phpcbf.bat --report=full -s -vv --standard=psr2
Problem with code:
Problem with code:
The text was updated successfully, but these errors were encountered: