Browse Source

MethodArgumentSpaceFixer - handle misplaced )

Dariusz Ruminski 5 years ago
parent
commit
75b55b529e

+ 6 - 6
src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php

@@ -317,13 +317,13 @@ final class MethodArgumentSpaceFixer extends AbstractFixer implements Configurat
         $indentation = $existingIndentation.$this->whitespacesConfig->getIndent();
         $endFunctionIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startFunctionIndex);
 
-        if (!$this->isNewline($tokens[$endFunctionIndex - 1])) {
-            $tokens->ensureWhitespaceAtIndex(
-                $endFunctionIndex,
-                0,
-                $this->whitespacesConfig->getLineEnding().$existingIndentation
-            );
+        $wasWhitespaceBeforeEndFunctionAddedAsNewToken = $tokens->ensureWhitespaceAtIndex(
+            $tokens[$endFunctionIndex - 1]->isWhitespace() ? $endFunctionIndex - 1 : $endFunctionIndex,
+            0,
+            $this->whitespacesConfig->getLineEnding().$existingIndentation
+        );
 
+        if ($wasWhitespaceBeforeEndFunctionAddedAsNewToken) {
             ++$endFunctionIndex;
         }
 

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

@@ -878,6 +878,25 @@ INPUT
                     'keep_multiple_spaces_after_comma' => true,
                 ],
             ],
+            'fix closing parenthesis (without trailing comma)' => [
+                '<?php
+if (true) {
+    execute(
+        $foo,
+        $bar
+    );
+}',
+                '<?php
+if (true) {
+    execute(
+        $foo,
+        $bar
+        );
+}',
+                [
+                    'on_multiline' => 'ensure_fully_multiline',
+                ],
+            ],
         ];
     }
 

+ 1 - 1
tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php

@@ -572,6 +572,6 @@ namespace {
         $this->doTest(
             '<?php $name = \get_class($foo, );',
             '<?php $name = get_class($foo, );'
-         );
+        );
     }
 }

+ 1 - 1
tests/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixerTest.php

@@ -158,7 +158,7 @@ EOF;
                  */
                 '.'
                 class Foo {}'
-            );
+        );
     }
 
     public function testLineWithSpacesIsRemovedWhenNextTokenIsNotIndented()

+ 1 - 1
tests/Fixer/Strict/StrictParamFixerTest.php

@@ -176,6 +176,6 @@ final class StrictParamFixerTest extends AbstractFixerTestCase
         $this->doTest(
             '<?php in_array($b, $c, true, );',
             '<?php in_array($b, $c, );'
-         );
+        );
     }
 }