Skip to content

Commit

Permalink
PEAR/FunctionCallSignature: minor tweaks
Browse files Browse the repository at this point in the history
Minor defensive coding and documentation improvements + an additional unit test.
  • Loading branch information
jrfnl committed Mar 2, 2023
1 parent ed8e00d commit a63f040
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ 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
if ($first !== false
&& $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
Expand Down Expand Up @@ -386,8 +387,10 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $

$fix = $phpcsFile->addFixableError($error, $first, 'OpeningIndent', $data);
if ($fix === true) {
// Set adjustment for use later to determine whether argument indentation is correct when fixing.
$adjustment = ($functionIndent - $foundFunctionIndent);
$padding = str_repeat(' ', $functionIndent);

$padding = str_repeat(' ', $functionIndent);
if ($foundFunctionIndent === 0) {
$phpcsFile->fixer->addContentBefore($first, $padding);
} else if ($tokens[$first]['code'] === T_INLINE_HTML) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,3 +567,10 @@ content
<p><?php require get_theme_file_path(
'/theme_extra/test_block.php'
); ?></p>

<!-- If the first token is inline HTML, the token itself should be adjusted, not the token before. -->
<?php if (check_me() == 'value'): ?>
<?php include get_file_path(
'my_file.php'
); ?>
<?php endif; ?>
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,10 @@ content
<p><?php require get_theme_file_path(
'/theme_extra/test_block.php'
); ?></p>

<!-- If the first token is inline HTML, the token itself should be adjusted, not the token before. -->
<?php if (check_me() == 'value'): ?>
<?php include get_file_path(
'my_file.php'
); ?>
<?php endif; ?>
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public function getErrorList($testFile='FunctionCallSignatureUnitTest.inc')
559 => 1,
567 => 1,
568 => 1,
573 => 1,
574 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit a63f040

Please sign in to comment.