Skip to content

Commit 50a20de

Browse files
committed
Fixed bug #2623 : PSR12.ControlStructures.ControlStructureSpacing not ignoring indentation inside multi-line string arguments
1 parent 0aa44e9 commit 50a20de

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
3131
- Fixed bug #2619 : PSR12.Files.FileHeader locks up when inline comment is the last content in a file
3232
- Fixed bug #2621 : PSR12.Classes.AnonClassDeclaration.CloseBraceSameLine false positive for anon class passed as function argument
3333
-- Thanks to Martins Sipenko for the patch
34+
- Fixed bug #2623 : PSR12.ControlStructures.ControlStructureSpacing not ignoring indentation inside multi-line string arguments
3435
- Fixed bug #2624 : PSR12.Traits.UseDeclaration doesnt apply the correct indent during auto fixing
3536
</notes>
3637
<contents>

src/Standards/PSR12/Sniffs/ControlStructures/ControlStructureSpacingSniff.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ public function process(File $phpcsFile, $stackPtr)
103103
break;
104104
}
105105

106+
// Leave indentation inside multi-line strings.
107+
if (isset(Tokens::$textStringTokens[$tokens[$i]['code']]) === true
108+
|| isset(Tokens::$heredocTokens[$tokens[$i]['code']]) === true
109+
) {
110+
continue;
111+
}
112+
106113
if ($tokens[$i]['code'] !== T_WHITESPACE) {
107114
$foundIndent = 0;
108115
} else {

src/Standards/PSR12/Tests/ControlStructures/ControlStructureSpacingUnitTest.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,16 @@ $i < 10;
6060
$i++;
6161
) {
6262
}
63+
64+
if (
65+
foo(
66+
'this
67+
is a
68+
string',
69+
<<<EOD
70+
foobar!
71+
EOD
72+
)
73+
) {
74+
return;
75+
}

src/Standards/PSR12/Tests/ControlStructures/ControlStructureSpacingUnitTest.inc.fixed

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,16 @@ for (
6161
$i++;
6262
) {
6363
}
64+
65+
if (
66+
foo(
67+
'this
68+
is a
69+
string',
70+
<<<EOD
71+
foobar!
72+
EOD
73+
)
74+
) {
75+
return;
76+
}

0 commit comments

Comments
 (0)