Skip to content

Commit 1477525

Browse files
committed
Fixed bug #1512 : PEAR.Functions.FunctionCallSignature enforces spaces when no arguments if required spaces is not 0
1 parent 53656de commit 1477525

File tree

5 files changed

+42
-23
lines changed

5 files changed

+42
-23
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
3535
-- Thanks to Vytautas Stankus for the patch
3636
- Squiz.Commenting.InlineComment incorrectly identified comment blocks in some cases, muting some errors
3737
-- Thanks to Juliette Reinders Folmer for the patch
38+
- Fixed bug #1512 : PEAR.Functions.FunctionCallSignature enforces spaces when no arguments if required spaces is not 0
3839
- Fixed bug #1522 : Squiz Arrays.ArrayDeclaration and Strings.ConcatenationSpacing fixers causing parse errors with here/nowdocs
3940
- Fixed bug #1570 : Squiz.Arrays.ArrayDeclaration fixer removes comments between array keyword and open parentheses
4041
- Fixed bug #1604 : File::isReference has problems with some bitwise operators and class property references

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,33 +205,43 @@ public function isMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $token
205205
*/
206206
public function processSingleLineCall(File $phpcsFile, $stackPtr, $openBracket, $tokens)
207207
{
208+
// If the function call has no arguments or comments, enforce 0 spaces.
208209
$closer = $tokens[$openBracket]['parenthesis_closer'];
209210
if ($openBracket === ($closer - 1)) {
210211
return;
211212
}
212213

213-
if ($this->requiredSpacesAfterOpen === 0 && $tokens[($openBracket + 1)]['code'] === T_WHITESPACE) {
214+
$next = $phpcsFile->findNext(T_WHITESPACE, ($openBracket + 1), $closer, true);
215+
if ($next === false) {
216+
$requiredSpacesAfterOpen = 0;
217+
$requiredSpacesBeforeClose = 0;
218+
} else {
219+
$requiredSpacesAfterOpen = $this->requiredSpacesAfterOpen;
220+
$requiredSpacesBeforeClose = $this->requiredSpacesBeforeClose;
221+
}
222+
223+
if ($requiredSpacesAfterOpen === 0 && $tokens[($openBracket + 1)]['code'] === T_WHITESPACE) {
214224
// Checking this: $value = my_function([*]...).
215225
$error = 'Space after opening parenthesis of function call prohibited';
216226
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterOpenBracket');
217227
if ($fix === true) {
218228
$phpcsFile->fixer->replaceToken(($openBracket + 1), '');
219229
}
220-
} else if ($this->requiredSpacesAfterOpen > 0) {
230+
} else if ($requiredSpacesAfterOpen > 0) {
221231
$spaceAfterOpen = 0;
222232
if ($tokens[($openBracket + 1)]['code'] === T_WHITESPACE) {
223233
$spaceAfterOpen = strlen($tokens[($openBracket + 1)]['content']);
224234
}
225235

226-
if ($spaceAfterOpen !== $this->requiredSpacesAfterOpen) {
236+
if ($spaceAfterOpen !== $requiredSpacesAfterOpen) {
227237
$error = 'Expected %s spaces after opening bracket; %s found';
228238
$data = array(
229-
$this->requiredSpacesAfterOpen,
239+
$requiredSpacesAfterOpen,
230240
$spaceAfterOpen,
231241
);
232242
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterOpenBracket', $data);
233243
if ($fix === true) {
234-
$padding = str_repeat(' ', $this->requiredSpacesAfterOpen);
244+
$padding = str_repeat(' ', $requiredSpacesAfterOpen);
235245
if ($spaceAfterOpen === 0) {
236246
$phpcsFile->fixer->addContent($openBracket, $padding);
237247
} else {
@@ -255,15 +265,15 @@ public function processSingleLineCall(File $phpcsFile, $stackPtr, $openBracket,
255265
$spaceBeforeClose = strlen($tokens[($closer - 1)]['content']);
256266
}
257267

258-
if ($spaceBeforeClose !== $this->requiredSpacesBeforeClose) {
268+
if ($spaceBeforeClose !== $requiredSpacesBeforeClose) {
259269
$error = 'Expected %s spaces before closing bracket; %s found';
260270
$data = array(
261-
$this->requiredSpacesBeforeClose,
271+
$requiredSpacesBeforeClose,
262272
$spaceBeforeClose,
263273
);
264274
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeCloseBracket', $data);
265275
if ($fix === true) {
266-
$padding = str_repeat(' ', $this->requiredSpacesBeforeClose);
276+
$padding = str_repeat(' ', $requiredSpacesBeforeClose);
267277

268278
if ($spaceBeforeClose === 0) {
269279
$phpcsFile->fixer->addContentBefore($closer, $padding);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ function foo()
213213
test($arg, $arg2);
214214
test( $arg, $arg2 );
215215
test( $arg, $arg2 );
216+
test();
217+
test( );
218+
test( );
216219
// @codingStandardsChangeSetting PEAR.Functions.FunctionCallSignature requiredSpacesAfterOpen 0
217220
// @codingStandardsChangeSetting PEAR.Functions.FunctionCallSignature requiredSpacesBeforeClose 0
218221

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ function foo()
218218
test( $arg, $arg2 );
219219
test( $arg, $arg2 );
220220
test( $arg, $arg2 );
221+
test();
222+
test();
223+
test();
221224
// @codingStandardsChangeSetting PEAR.Functions.FunctionCallSignature requiredSpacesAfterOpen 0
222225
// @codingStandardsChangeSetting PEAR.Functions.FunctionCallSignature requiredSpacesBeforeClose 0
223226

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,24 @@ public function getErrorList($testFile='FunctionCallSignatureUnitTest.inc')
8181
194 => 1,
8282
213 => 2,
8383
215 => 2,
84-
274 => 1,
85-
275 => 1,
86-
300 => 1,
87-
305 => 1,
88-
318 => 1,
89-
319 => 1,
90-
326 => 1,
91-
327 => 1,
92-
334 => 1,
93-
339 => 1,
94-
340 => 1,
84+
217 => 2,
85+
218 => 2,
86+
277 => 1,
87+
278 => 1,
88+
303 => 1,
89+
308 => 1,
90+
321 => 1,
91+
322 => 1,
92+
329 => 1,
93+
330 => 1,
94+
337 => 1,
9595
342 => 1,
96-
343 => 2,
97-
350 => 1,
98-
351 => 1,
99-
352 => 2,
96+
343 => 1,
97+
345 => 1,
98+
346 => 2,
99+
353 => 1,
100+
354 => 1,
101+
355 => 2,
100102
);
101103

102104
}//end getErrorList()

0 commit comments

Comments
 (0)