Skip to content

Commit

Permalink
PSR2, PSR12, and PEAR standards now correctly check for blank lines a…
Browse files Browse the repository at this point in the history
…t the start of function calls (ref #2630)
  • Loading branch information
gsherwood committed Oct 9, 2019
1 parent 33af624 commit e487b6e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Output is printed when running PHPCS with the --report=diff and -vvv command line arguments
-- Fully qualified class names have been replaced with sniff codes
-- Tokens being changed now display the line number they are on
- PSR2, PSR12, and PEAR standards now correctly check for blank lines at the start of function calls
-- This check has been missing from these standards, but has now been implemented
-- When using the PEAR standard, the error code is PEAR.Functions.FunctionCallSignature.FirstArgumentPosition
-- When using PSR2 or PSR12, the error code is PSR2.Methods.FunctionCallSignature.FirstArgumentPosition
- PSR12.Files.FileHeader no longer ignores comments preceding a use, namespace, or declare statement
- PSR12.Files.FileHeader now allows a hashbang line at the top of the file
- Fixed bug #2615 : Constant visibility false positive on non-class constants
Expand Down
22 changes: 22 additions & 0 deletions src/Standards/PEAR/Sniffs/Functions/FunctionCallSignatureSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,28 @@ public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $

// Start processing at the first argument.
$i = $phpcsFile->findNext(T_WHITESPACE, ($openBracket + 1), null, true);

if ($tokens[$i]['line'] > ($tokens[$openBracket]['line'] + 1)) {
$error = 'The first argument in a multi-line function call must be on the line after the opening parenthesis';
$fix = $phpcsFile->addFixableError($error, $i, 'FirstArgumentPosition');
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
for ($x = ($openBracket + 1); $x < $i; $x++) {
if ($tokens[$x]['line'] === $tokens[$openBracket]['line']) {
continue;
}

if ($tokens[$x]['line'] === $tokens[$i]['line']) {
break;
}

$phpcsFile->fixer->replaceToken($x, '');
}

$phpcsFile->fixer->endChangeset();
}
}//end if

if ($tokens[($i - 1)]['code'] === T_WHITESPACE
&& $tokens[($i - 1)]['line'] === $tokens[$i]['line']
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,18 @@ functionCall(
);

// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments true

$this->foo(

['a','b'],
true

);

$this->foo(

// Comment
['a','b'],
true

);
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,14 @@ functionCall(
);

// phpcs:set PEAR.Functions.FunctionCallSignature allowMultipleArguments true

$this->foo(
['a','b'],
true
);

$this->foo(
// Comment
['a','b'],
true
);
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public function getErrorList($testFile='FunctionCallSignatureUnitTest.inc')
395 => 1,
396 => 1,
411 => 1,
422 => 1,
424 => 1,
429 => 1,
432 => 1,
];

}//end getErrorList()
Expand Down

0 comments on commit e487b6e

Please sign in to comment.