Skip to content

Commit 82ed7d1

Browse files
committed
bug #4436 MethodArgumentSpaceFixer - handle misplaced ) (keradus)
This PR was merged into the 2.12 branch. Discussion ---------- MethodArgumentSpaceFixer - handle misplaced ) Commits ------- 75b55b5 MethodArgumentSpaceFixer - handle misplaced )
2 parents d225596 + 75b55b5 commit 82ed7d1

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,13 @@ private function ensureFunctionFullyMultiline(Tokens $tokens, $startFunctionInde
317317
$indentation = $existingIndentation.$this->whitespacesConfig->getIndent();
318318
$endFunctionIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startFunctionIndex);
319319

320-
if (!$this->isNewline($tokens[$endFunctionIndex - 1])) {
321-
$tokens->ensureWhitespaceAtIndex(
322-
$endFunctionIndex,
323-
0,
324-
$this->whitespacesConfig->getLineEnding().$existingIndentation
325-
);
320+
$wasWhitespaceBeforeEndFunctionAddedAsNewToken = $tokens->ensureWhitespaceAtIndex(
321+
$tokens[$endFunctionIndex - 1]->isWhitespace() ? $endFunctionIndex - 1 : $endFunctionIndex,
322+
0,
323+
$this->whitespacesConfig->getLineEnding().$existingIndentation
324+
);
326325

326+
if ($wasWhitespaceBeforeEndFunctionAddedAsNewToken) {
327327
++$endFunctionIndex;
328328
}
329329

tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,25 @@ function foo(
878878
'keep_multiple_spaces_after_comma' => true,
879879
],
880880
],
881+
'fix closing parenthesis (without trailing comma)' => [
882+
'<?php
883+
if (true) {
884+
execute(
885+
$foo,
886+
$bar
887+
);
888+
}',
889+
'<?php
890+
if (true) {
891+
execute(
892+
$foo,
893+
$bar
894+
);
895+
}',
896+
[
897+
'on_multiline' => 'ensure_fully_multiline',
898+
],
899+
],
881900
];
882901
}
883902

tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,6 @@ public function testFix73()
572572
$this->doTest(
573573
'<?php $name = \get_class($foo, );',
574574
'<?php $name = get_class($foo, );'
575-
);
575+
);
576576
}
577577
}

tests/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Foo {}',
158158
*/
159159
'.'
160160
class Foo {}'
161-
);
161+
);
162162
}
163163

164164
public function testLineWithSpacesIsRemovedWhenNextTokenIsNotIndented()

tests/Fixer/Strict/StrictParamFixerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,6 @@ public function testFix73()
176176
$this->doTest(
177177
'<?php in_array($b, $c, true, );',
178178
'<?php in_array($b, $c, );'
179-
);
179+
);
180180
}
181181
}

0 commit comments

Comments
 (0)