Skip to content

Commit

Permalink
Merge branch 'feature/2562-squiz-controlsignature-fix-false-positive-…
Browse files Browse the repository at this point in the history
…inline-controlstructure' of https://github.com/jrfnl/PHP_CodeSniffer
  • Loading branch information
gsherwood committed Jul 31, 2019
2 parents 9ae59b2 + 5cf397d commit 49f5a07
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,26 @@ public function process(File $phpcsFile, $stackPtr)
}
}//end if
} else if ($tokens[$stackPtr]['code'] === T_WHILE) {
// Zero spaces after parenthesis closer.
$closer = $tokens[$stackPtr]['parenthesis_closer'];
$found = 0;
if ($tokens[($closer + 1)]['code'] === T_WHITESPACE) {
if (strpos($tokens[($closer + 1)]['content'], $phpcsFile->eolChar) !== false) {
$found = 'newline';
} else {
$found = $tokens[($closer + 1)]['length'];
// Zero spaces after parenthesis closer, but only if followed by a semicolon.
$closer = $tokens[$stackPtr]['parenthesis_closer'];
$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($closer + 1), null, true);
if ($nextNonEmpty !== false && $tokens[$nextNonEmpty]['code'] === T_SEMICOLON) {
$found = 0;
if ($tokens[($closer + 1)]['code'] === T_WHITESPACE) {
if (strpos($tokens[($closer + 1)]['content'], $phpcsFile->eolChar) !== false) {
$found = 'newline';
} else {
$found = $tokens[($closer + 1)]['length'];
}
}
}

if ($found !== 0) {
$error = 'Expected 0 spaces before semicolon; %s found';
$data = [$found];
$fix = $phpcsFile->addFixableError($error, $closer, 'SpaceBeforeSemicolon', $data);
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($closer + 1), '');
if ($found !== 0) {
$error = 'Expected 0 spaces before semicolon; %s found';
$data = [$found];
$fix = $phpcsFile->addFixableError($error, $closer, 'SpaceBeforeSemicolon', $data);
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($closer + 1), '');
}
}
}
}//end if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,15 @@ if ($this) {
foo(${$a[$b]});
}

while ( $level-- ) ob_end_clean();

while ( $level-- )
ob_end_clean();

while ( $level-- ):
ob_end_clean();
endwhile;

// Intentional parse error. This should be the last test in the file.
foreach
// Some unrelated comment.
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ if ($this) {
foo(${$a[$b]});
}

while ( $level-- ) ob_end_clean();

while ( $level-- )
ob_end_clean();

while ( $level-- ):
ob_end_clean();
endwhile;

// Intentional parse error. This should be the last test in the file.
foreach
// Some unrelated comment.

0 comments on commit 49f5a07

Please sign in to comment.