Browse Source

bug #2827 MethodArgumentSpaceFixer - Always remove trailing spaces (julienfalque)

This PR was merged into the 2.2 branch.

Discussion
----------

MethodArgumentSpaceFixer - Always remove trailing spaces

Option `keep_multiple_spaces_after_comma` shoud not apply to trailing spaces IMO.

Ref: https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/2440#issuecomment-306912730

Commits
-------

e19728bf Always remove trailing spaces
Dariusz Ruminski 7 years ago
parent
commit
a897664741

+ 4 - 1
src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php

@@ -157,7 +157,10 @@ final class MethodArgumentSpaceFixer extends AbstractFixer implements Configurat
         //  1) multiple spaces after comma
         //  2) no space after comma
         if ($nextToken->isWhitespace()) {
-            if ($this->configuration['keep_multiple_spaces_after_comma'] || $this->isCommentLastLineToken($tokens, $index + 2)) {
+            if (
+                ($this->configuration['keep_multiple_spaces_after_comma'] && !preg_match('/\R/', $nextToken->getContent()))
+                || $this->isCommentLastLineToken($tokens, $index + 2)
+            ) {
                 return;
             }
 

+ 5 - 0
tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php

@@ -250,6 +250,11 @@ EOTXTb
 $a#
 );',
             ),
+            array(
+                "<?php xyz(\$a=10,\n\$b=20);",
+                "<?php xyz(\$a=10,   \n\$b=20);",
+                array('keep_multiple_spaces_after_comma' => true),
+            ),
         );
     }