diff --git a/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php b/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php index 782a733aa5..0ad6cf4fc4 100644 --- a/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php +++ b/src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php @@ -511,6 +511,12 @@ public function processMultiLineCall(File $phpcsFile, int $stackPtr, int $openBr $expectedIndent = ($foundFunctionIndent + $this->indent + $adjustment); } + if ($tokens[$i]['code'] === T_END_HEREDOC + || $tokens[$i]['code'] === T_END_NOWDOC + ) { + continue; + } + if ($tokens[$i]['code'] !== T_WHITESPACE && $tokens[$i]['code'] !== T_DOC_COMMENT_WHITESPACE ) { @@ -551,7 +557,10 @@ public function processMultiLineCall(File $phpcsFile, int $stackPtr, int $openBr $padding = str_repeat(' ', $expectedIndent); if ($foundIndent === 0) { $phpcsFile->fixer->addContentBefore($i, $padding); - if (isset($tokens[$i]['scope_opener']) === true) { + if (isset($tokens[$i]['scope_opener']) === true + && $tokens[$i]['code'] !== T_START_HEREDOC + && $tokens[$i]['code'] !== T_START_NOWDOC + ) { $phpcsFile->fixer->changeCodeBlockIndent($i, $tokens[$i]['scope_closer'], $expectedIndent); } } else { @@ -562,7 +571,10 @@ public function processMultiLineCall(File $phpcsFile, int $stackPtr, int $openBr $phpcsFile->fixer->replaceToken($i, $padding); } - if (isset($tokens[($i + 1)]['scope_opener']) === true) { + if (isset($tokens[($i + 1)]['scope_opener']) === true + && $tokens[($i + 1)]['code'] !== T_START_HEREDOC + && $tokens[($i + 1)]['code'] !== T_START_NOWDOC + ) { $phpcsFile->fixer->changeCodeBlockIndent(($i + 1), $tokens[($i + 1)]['scope_closer'], ($expectedIndent - $foundIndent)); } } diff --git a/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc b/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc index 3006081105..7ccfe2b11b 100644 --- a/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc +++ b/src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc @@ -609,3 +609,10 @@ $anon = new class () {}; // And anonymous object instantiations without parentheses are ignored. $anon = new class {}; + +// Flexible heredoc in multiline function call. + 1, 604 => 1, 605 => 2, + 615 => 1, ]; }