diff --git a/lib/PhpParser/PrettyPrinterAbstract.php b/lib/PhpParser/PrettyPrinterAbstract.php index 448bc84919..12ac7e0b74 100644 --- a/lib/PhpParser/PrettyPrinterAbstract.php +++ b/lib/PhpParser/PrettyPrinterAbstract.php @@ -765,7 +765,13 @@ protected function p( $pos = $subEndPos + 1; } - $result .= $this->origTokens->getTokenCode($pos, $endPos + 1, $indentAdjustment); + $tokenCode = $this->origTokens->getTokenCode($pos, $endPos + 1, $indentAdjustment); + if ($node instanceof Expr\CallLike && $node->isFirstClassCallable()) { + $tokenCode = str_replace(',', '', $tokenCode); + } + + $result .= $tokenCode; + return $result; } diff --git a/test/code/formatPreservation/args_to_variadic_remove_trailing_comma.test b/test/code/formatPreservation/args_to_variadic_remove_trailing_comma.test new file mode 100644 index 0000000000..6619002038 --- /dev/null +++ b/test/code/formatPreservation/args_to_variadic_remove_trailing_comma.test @@ -0,0 +1,38 @@ +Replace args with VariadicPlaceholder should remove trailing comma +----- + strlen(1 , 2 , 3 ,); + +strlen( + 'multiple new lines' + + , +); +----- +$stmts[0]->expr->args = [new Node\VariadicPlaceholder()]; +$stmts[1]->expr->args = [new Node\VariadicPlaceholder()]; +$stmts[2]->expr->right->args = [new Node\VariadicPlaceholder()]; +$stmts[3]->expr->args = [new Node\VariadicPlaceholder()]; +----- + strlen(...); + +strlen( + ... + + +);