Skip to content

Commit e487b6e

Browse files
committed
PSR2, PSR12, and PEAR standards now correctly check for blank lines at the start of function calls (ref #2630)
1 parent 33af624 commit e487b6e

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

package.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
3030
-- Output is printed when running PHPCS with the --report=diff and -vvv command line arguments
3131
-- Fully qualified class names have been replaced with sniff codes
3232
-- Tokens being changed now display the line number they are on
33+
- PSR2, PSR12, and PEAR standards now correctly check for blank lines at the start of function calls
34+
-- This check has been missing from these standards, but has now been implemented
35+
-- When using the PEAR standard, the error code is PEAR.Functions.FunctionCallSignature.FirstArgumentPosition
36+
-- When using PSR2 or PSR12, the error code is PSR2.Methods.FunctionCallSignature.FirstArgumentPosition
3337
- PSR12.Files.FileHeader no longer ignores comments preceding a use, namespace, or declare statement
3438
- PSR12.Files.FileHeader now allows a hashbang line at the top of the file
3539
- Fixed bug #2615 : Constant visibility false positive on non-class constants

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,28 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $
421421

422422
// Start processing at the first argument.
423423
$i = $phpcsFile->findNext(T_WHITESPACE, ($openBracket + 1), null, true);
424+
425+
if ($tokens[$i]['line'] > ($tokens[$openBracket]['line'] + 1)) {
426+
$error = 'The first argument in a multi-line function call must be on the line after the opening parenthesis';
427+
$fix = $phpcsFile->addFixableError($error, $i, 'FirstArgumentPosition');
428+
if ($fix === true) {
429+
$phpcsFile->fixer->beginChangeset();
430+
for ($x = ($openBracket + 1); $x < $i; $x++) {
431+
if ($tokens[$x]['line'] === $tokens[$openBracket]['line']) {
432+
continue;
433+
}
434+
435+
if ($tokens[$x]['line'] === $tokens[$i]['line']) {
436+
break;
437+
}
438+
439+
$phpcsFile->fixer->replaceToken($x, '');
440+
}
441+
442+
$phpcsFile->fixer->endChangeset();
443+
}
444+
}//end if
445+
424446
if ($tokens[($i - 1)]['code'] === T_WHITESPACE
425447
&& $tokens[($i - 1)]['line'] === $tokens[$i]['line']
426448
) {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,18 @@ functionCall(
416416
);
417417

418418
// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments true
419+
420+
$this->foo(
421+
422+
['a','b'],
423+
true
424+
425+
);
426+
427+
$this->foo(
428+
429+
// Comment
430+
['a','b'],
431+
true
432+
433+
);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,14 @@ functionCall(
430430
);
431431

432432
// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments true
433+
434+
$this->foo(
435+
['a','b'],
436+
true
437+
);
438+
439+
$this->foo(
440+
// Comment
441+
['a','b'],
442+
true
443+
);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public function getErrorList($testFile='FunctionCallSignatureUnitTest.inc')
112112
395 => 1,
113113
396 => 1,
114114
411 => 1,
115+
422 => 1,
116+
424 => 1,
117+
429 => 1,
118+
432 => 1,
115119
];
116120

117121
}//end getErrorList()

0 commit comments

Comments
 (0)