Skip to content

Commit

Permalink
Slight improvements + changelog for bug #1347
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Feb 17, 2017
1 parent dca8343 commit eff63ec
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,25 @@ public function processSingleLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeCloseBracket', $data);
if ($fix === true) {
$padding = str_repeat(' ', $this->requiredSpacesBeforeClose);

if ($spaceBeforeClose === 0) {
$phpcsFile->fixer->addContentBefore($closer, $padding);
} else {
} else if ($spaceBeforeClose === 'newline') {
$phpcsFile->fixer->beginChangeset();
$prev = ($closer - 1);

// We want to jump over any whitespace or inline comment and move the `)` after any other token.
$closingContent = ')';

$next = $phpcsFile->findNext(T_WHITESPACE, ($closer + 1), null, true);
if ($tokens[$next]['code'] === T_SEMICOLON) {
$closingContent .= ';';
for ($i = ($closer + 1); $i <= $next; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}
}

// We want to jump over any whitespace or inline comment and
// move the closing parenthesis after any other token.
$prev = ($closer - 1);
while (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$prev]['code']]) === true) {
if (($tokens[$prev]['code'] === T_COMMENT)
&& (strpos($tokens[$prev]['content'], '*/') !== false)
Expand All @@ -280,14 +292,16 @@ public function processSingleLineCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr
$prev--;
}

$phpcsFile->fixer->addContent($prev, $padding.')');
$phpcsFile->fixer->addContent($prev, $padding.$closingContent);

$prevNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, ($closer - 1), null, true);
for ($i = ($prevNonWhitespace + 1); $i <= $closer; $i++) {
$phpcsFile->fixer->replaceToken($i, '');
}

$phpcsFile->fixer->endChangeset();
} else {
$phpcsFile->fixer->replaceToken(($closer - 1), $padding);
}//end if
}//end if
}//end if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,39 @@ foo('Testing
// . $text2
*/
);
// @codingStandardsChangeSetting PSR2.Methods.FunctionCallSignature requiredSpacesBeforeClose 0
// @codingStandardsChangeSetting PSR2.Methods.FunctionCallSignature requiredSpacesBeforeClose 0

foo('Testing
multiline text'
);

foo('Testing
multiline text'
);

foo('Testing
multiline text' // hello
);

foo('Testing
multiline text' /* hello */
);

foo('Testing
multiline text'
// hello
);

foo('Testing
multiline text'
/* hello */
);

$var = foo('Testing
multiline'
// hi
) + foo('Testing
multiline'
// hi
)
;
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,50 @@ foo('Testing
multiline text' );

foo('Testing
multiline text: ' ) // . $text
;
multiline text: ' ); // . $text


foo('Testing
multiline text: ' /* . $text */ );

foo('Testing
multiline text: ' /* . $text */ )
multiline text: ' /* . $text */ );
// . $other_text
;


foo('Testing
multiline text: ' /*
. $text
// . $text2
*/ );
// @codingStandardsChangeSetting PSR2.Methods.FunctionCallSignature requiredSpacesBeforeClose 0
// @codingStandardsChangeSetting PSR2.Methods.FunctionCallSignature requiredSpacesBeforeClose 0

foo('Testing
multiline text');

foo('Testing
multiline text');

foo('Testing
multiline text'); // hello


foo('Testing
multiline text' /* hello */);

foo('Testing
multiline text');
// hello


foo('Testing
multiline text'
/* hello */);

$var = foo('Testing
multiline')
// hi
+ foo('Testing
multiline');
// hi

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public function getErrorList()
129 => 1,
133 => 1,
138 => 1,
146 => 1,
150 => 1,
154 => 1,
158 => 1,
162 => 1,
167 => 1,
172 => 1,
175 => 1,
178 => 1,
);

}//end getErrorList()
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #1340 : STDIN file contents not being populated in some cases
-- Thanks to David Biňovec for the patch
- Fixed bug #1344 : PEAR.Functions.FunctionCallSignatureSniff throws error for blank comment lines
- Fixed bug #1347 : PSR2.Methods.FunctionCallSignature strips some comments during fixing
-- Thanks to Algirdas Gurevicius for the patch
- Fixed bug #1349 : Squiz.Strings.DoubleQuoteUsage.NotRequired message is badly formatted when string contains a CR newline char
-- Thanks to Algirdas Gurevicius for the patch
- Fixed bug #1350 : Invalid Squiz.Formatting.OperatorBracket error when using namespaces
Expand Down

0 comments on commit eff63ec

Please sign in to comment.