diff --git a/src/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php b/src/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php index 136a1d4ae9..39fdae9526 100644 --- a/src/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php +++ b/src/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php @@ -156,10 +156,13 @@ public function checkSpacing(File $phpcsFile, $stackPtr, $openBracket) }//end if if ($tokens[($nextSeparator + 1)]['code'] !== T_WHITESPACE) { - $error = 'No space found after comma in argument list'; - $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'NoSpaceAfterComma'); - if ($fix === true) { - $phpcsFile->fixer->addContent($nextSeparator, ' '); + // Ignore trailing comma's after last argument as that's outside the scope of this sniff. + if (($nextSeparator + 1) !== $closeBracket) { + $error = 'No space found after comma in argument list'; + $fix = $phpcsFile->addFixableError($error, $nextSeparator, 'NoSpaceAfterComma'); + if ($fix === true) { + $phpcsFile->fixer->addContent($nextSeparator, ' '); + } } } else { // If there is a newline in the space, then they must be formatting diff --git a/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc b/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc index 7c86a89f01..8bd067b3f9 100644 --- a/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc +++ b/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc @@ -162,3 +162,13 @@ class Testing extends Bar $a = new parent($foo ,$bar); } } + +// Ignore spacing after PHP 7.3+ trailing comma in single-line function calls to prevent fixer conflicts. +// This is something which should be decided by a sniff dealing with the function call parentheses. +$foo = new MyClass($obj, 'getMethod',); +$foo = new MyClass($obj, 'getMethod', ); +$foo = new MyClass($obj, 'getMethod', ); +$foo = new MyClass( + $obj, + 'getMethod', +); diff --git a/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc.fixed b/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc.fixed index 8c9800725a..69676524dc 100644 --- a/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc.fixed +++ b/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.inc.fixed @@ -162,3 +162,13 @@ class Testing extends Bar $a = new parent($foo, $bar); } } + +// Ignore spacing after PHP 7.3+ trailing comma in single-line function calls to prevent fixer conflicts. +// This is something which should be decided by a sniff dealing with the function call parentheses. +$foo = new MyClass($obj, 'getMethod',); +$foo = new MyClass($obj, 'getMethod', ); +$foo = new MyClass($obj, 'getMethod', ); +$foo = new MyClass( + $obj, + 'getMethod', +); diff --git a/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.php b/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.php index 789b60b37c..5f87962e62 100644 --- a/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.php +++ b/src/Standards/Generic/Tests/Functions/FunctionCallArgumentSpacingUnitTest.php @@ -55,6 +55,7 @@ public function getErrorList() 154 => 2, 155 => 1, 162 => 2, + 170 => 1, ]; }//end getErrorList()