Skip to content

Commit

Permalink
Avoid conflicts with Generic.WhiteSpace.ScopeIndent
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Apr 30, 2024
1 parent ddd7f72 commit 810f747
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
12 changes: 10 additions & 2 deletions src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $
// We need to work out how far indented the function
// call itself is, so we can work out how far to
// indent the arguments.
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true);
$first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_INLINE_HTML], $stackPtr, true);
if ($first !== false
&& $tokens[$first]['code'] === T_CONSTANT_ENCAPSED_STRING
&& $tokens[($first - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING
Expand Down Expand Up @@ -666,6 +666,14 @@ protected function complainOpenStatementWrongIndent(
return;
}

$firstToken = $tokens[$first];
if ($firstToken['code'] === T_OPEN_TAG || $firstToken['code'] === T_OPEN_TAG_WITH_ECHO) {
$prevToken = $tokens[($first - 1)];
if ($prevToken !== false && $firstToken['line'] === $prevToken['line']) {
return;
}
}

$error = 'Opening statement of multi-line function call not indented correctly; expected %s spaces but found %s';
$data = [
$functionIndent,
Expand All @@ -684,7 +692,7 @@ protected function complainOpenStatementWrongIndent(
} else if ($tokens[$first]['code'] === T_INLINE_HTML) {
$newContent = $padding.ltrim($tokens[$first]['content']);
$phpcsFile->fixer->replaceToken($first, $newContent);
} else {
} else if ($tokens[($first - 1)]['code'] === T_WHITESPACE) {
$phpcsFile->fixer->replaceToken(($first - 1), $padding);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ test();
?>
<script>
var foo = <?php echo bar(
'baz'
); ?>;
'baz'
); ?>;
</script>
<script>
var foo = <?php echo bar(
'baz'
); ?>;
'baz'
); ?>;
</script>
<?php

Expand Down Expand Up @@ -567,27 +567,27 @@ array_fill_keys(
?>
<div>
<p/><?php require get_theme_file_path(
'/theme_extra/test_block.php'
); ?></p>
'/theme_extra/test_block.php'
); ?></p>
</div>
<div>
<p/><?php require get_theme_file_path(
'/theme_extra/test_block.php'
); ?></p>
<p/><?php require get_theme_file_path(
'/theme_extra/test_block.php'
); ?></p>
</div>
<?php
echo 'hi';
?>
content
<p><?php require get_theme_file_path(
'/theme_extra/test_block.php'
<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(
<?php include get_file_path(
'my_file.php'
); ?>
); ?>
<?php endif; ?>

<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public function getErrorList($testFile='')
215 => 2,
217 => 2,
218 => 2,
225 => 1,
226 => 1,
230 => 1,
231 => 1,
277 => 1,
278 => 1,
303 => 1,
Expand Down Expand Up @@ -130,10 +134,11 @@ public function getErrorList($testFile='')
546 => 1,
547 => 1,
548 => 1,
559 => 1,
567 => 1,
555 => 1,
556 => 1,
560 => 1,
561 => 1,
568 => 1,
573 => 1,
581 => 1,
587 => 1,
594 => 1,
Expand Down

0 comments on commit 810f747

Please sign in to comment.