Skip to content

Commit

Permalink
PSR2.ControlStructures.ControlStructureSpacing now checks whitespace …
Browse files Browse the repository at this point in the history
…before the closing parenthesis of multi-line control structures (ref #2499)
  • Loading branch information
gsherwood committed Nov 11, 2019
1 parent ebc9b7a commit df7af3c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Generic.CodeAnalysis.EmptyPhpStatement now reports unnecessary semicolons after control structure closing braces
-- Thanks to Vincent Langlet for the patch
- Generic.WhiteSpace.ScopeIndent now supports static arrow functions
- PSR2.ControlStructures.ControlStructureSpacing now checks whitespace before the closing parenthesis of multi-line control structures
-- Previously, it incorrectly applied the whitespace check for single-line definitions only
- Fixed bug #2638 : Squiz.CSS.DuplicateClassDefinitionSniff sees comments as part of the class name
-- Thanks to Raphael Horber for the patch
- Fixed bug #2674 : Squiz.Functions.FunctionDeclarationArgumentSpacing prints wrong argument name in error message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public function process(File $phpcsFile, $stackPtr)
}
}//end if

if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line']) {
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($parenCloser - 1), $parenOpener, true);
if ($tokens[$prev]['line'] === $tokens[$parenCloser]['line']) {
$spaceBeforeClose = 0;
if ($tokens[($parenCloser - 1)]['code'] === T_WHITESPACE) {
$spaceBeforeClose = strlen(ltrim($tokens[($parenCloser - 1)]['content'], $phpcsFile->eolChar));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,16 @@ foreach ( $something as $blah => $that ) {}
// phpcs:set PSR2.ControlStructures.ControlStructureSpacing requiredSpacesBeforeClose 0

$binary = b"binary string";

if ($expr1
&& $expr2 ) {
}

if ($expr1
&& $expr2 /* comment */ ) {
}

if ($expr1
&& $expr2
/* comment */ ) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,16 @@ foreach ( $something as $blah => $that ) {}
// phpcs:set PSR2.ControlStructures.ControlStructureSpacing requiredSpacesBeforeClose 0

$binary = b"binary string";

if ($expr1
&& $expr2) {
}

if ($expr1
&& $expr2 /* comment */) {
}

if ($expr1
&& $expr2
/* comment */) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public function getErrorList()
31 => 1,
51 => 2,
53 => 2,
60 => 1,
64 => 1,
69 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit df7af3c

Please sign in to comment.