Skip to content

Commit 3c80ec8

Browse files
authored
Merge pull request #134 from PHPCSStandards/feature/pear-functioncallsignature-minor-tweaks
PEAR/FunctionCallSignature: minor tweaks
2 parents a96d0ee + 57c4088 commit 3c80ec8

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $
340340
// call itself is, so we can work out how far to
341341
// indent the arguments.
342342
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true);
343-
if ($tokens[$first]['code'] === T_CONSTANT_ENCAPSED_STRING
343+
if ($first !== false
344+
&& $tokens[$first]['code'] === T_CONSTANT_ENCAPSED_STRING
344345
&& $tokens[($first - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING
345346
) {
346347
// We are in a multi-line string, so find the start and use
@@ -386,8 +387,10 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $
386387

387388
$fix = $phpcsFile->addFixableError($error, $first, 'OpeningIndent', $data);
388389
if ($fix === true) {
390+
// Set adjustment for use later to determine whether argument indentation is correct when fixing.
389391
$adjustment = ($functionIndent - $foundFunctionIndent);
390-
$padding = str_repeat(' ', $functionIndent);
392+
393+
$padding = str_repeat(' ', $functionIndent);
391394
if ($foundFunctionIndent === 0) {
392395
$phpcsFile->fixer->addContentBefore($first, $padding);
393396
} else if ($tokens[$first]['code'] === T_INLINE_HTML) {

src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,10 @@ content
567567
<p><?php require get_theme_file_path(
568568
'/theme_extra/test_block.php'
569569
); ?></p>
570+
571+
<!-- If the first token is inline HTML, the token itself should be adjusted, not the token before. -->
572+
<?php if (check_me() == 'value'): ?>
573+
<?php include get_file_path(
574+
'my_file.php'
575+
); ?>
576+
<?php endif; ?>

src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.inc.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,3 +582,10 @@ content
582582
<p><?php require get_theme_file_path(
583583
'/theme_extra/test_block.php'
584584
); ?></p>
585+
586+
<!-- If the first token is inline HTML, the token itself should be adjusted, not the token before. -->
587+
<?php if (check_me() == 'value'): ?>
588+
<?php include get_file_path(
589+
'my_file.php'
590+
); ?>
591+
<?php endif; ?>

src/Standards/PEAR/Tests/Functions/FunctionCallSignatureUnitTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public function getErrorList($testFile='FunctionCallSignatureUnitTest.inc')
134134
559 => 1,
135135
567 => 1,
136136
568 => 1,
137+
573 => 1,
138+
574 => 1,
137139
];
138140

139141
}//end getErrorList()

0 commit comments

Comments
 (0)