Skip to content

Commit

Permalink
Additional fix for #2506
Browse files Browse the repository at this point in the history
Slightly different fix for the second code snippet reported there. Uses startOfStatement instead of line unless it detects method chaining.
  • Loading branch information
gsherwood committed Oct 11, 2019
1 parent c11b324 commit da72d36
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,11 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $
// call itself is, so we can work out how far to
// indent the arguments.
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true);
if ($tokens[$first]['code'] === T_CONSTANT_ENCAPSED_STRING
&& $tokens[($first - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING
) {
// We are in a multi-line string, so find the start and use
// the indent from there.
$prev = $phpcsFile->findPrevious(T_CONSTANT_ENCAPSED_STRING, ($first - 2), null, true);
$first = $phpcsFile->findFirstOnLine(Tokens::$emptyTokens, $prev, true);
if ($tokens[$first]['code'] !== T_OBJECT_OPERATOR) {
// This is not a chained method, so go back and look for the
// start of the statement and take our indent from there.
$start = $phpcsFile->findStartOfStatement($stackPtr, true);
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $start, true);
}

$foundFunctionIndent = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,18 @@ function m()
) . '
' : '');
}

class C
{

public function m()
{
$a = [];
$t =
"SELECT * FROM t
WHERE f IN(" . implode(
",",
$a
) . ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,18 @@ function m()
) . '
' : '');
}

class C
{

public function m()
{
$a = [];
$t =
"SELECT * FROM t
WHERE f IN(" . implode(
",",
$a
) . ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public function getErrorList($testFile='FunctionCallSignatureUnitTest.inc')
440 => 1,
441 => 1,
442 => 1,
455 => 1,
456 => 1,
457 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit da72d36

Please sign in to comment.