diff --git a/src/CodeGenerator.php b/src/CodeGenerator.php index e5bc9d7..b844277 100644 --- a/src/CodeGenerator.php +++ b/src/CodeGenerator.php @@ -639,7 +639,7 @@ public function dumpCall( } yield sprintf('->%s(', $method); - yield Group::indent($addCommaAfterEachArgument ? $this->allSuffix(',', $args) : $args); + yield Group::indent($addCommaAfterEachArgument ? $this->allSuffix(',', $args) : $this->suffixLast(',', $args)); yield ')'; }); @@ -668,7 +668,7 @@ public function dumpCall( } yield sprintf('%s(', $call); - yield Group::indent($addCommaAfterEachArgument ? $this->allSuffix(',', $args) : $args); + yield Group::indent($addCommaAfterEachArgument ? $this->allSuffix(',', $args) : $this->suffixLast(',', $args)); yield ')'; } diff --git a/tests/CodeGeneratorTest.php b/tests/CodeGeneratorTest.php index dcb4f69..03038de 100644 --- a/tests/CodeGeneratorTest.php +++ b/tests/CodeGeneratorTest.php @@ -1025,6 +1025,51 @@ public function testDumpCallWithMultipleArgsOnIterable() : void ); } + public function testDumpCallWithoutCommaAfterEachArgumentAddsTrailingComma() : void + { + $this->assertDump( + <<<'PHP' + Helper::process( + match (true) { + $a => 1, + default => 2, + }, + ) + PHP, + $this->generator->dumpCall('App\\Utils\\Helper', 'process', [ + 'match (true) {', + $this->generator->indent(function () { + yield '$a => 1,'; + yield 'default => 2,'; + }), + '}', + ], true, false), + ); + } + + public function testDumpCallOnIterableWithoutCommaAfterEachArgumentAddsTrailingComma() : void + { + $this->assertDump( + <<<'PHP' + $object + ->method( + match (true) { + $a => 1, + default => 2, + }, + ) + PHP, + $this->generator->dumpCall(['$object'], 'method', [ + 'match (true) {', + $this->generator->indent(function () { + yield '$a => 1,'; + yield 'default => 2,'; + }), + '}', + ], false, false), + ); + } + public function testDumpFileWithNoImportsHasNoExtraNewline() : void { $this->generator = new CodeGenerator('App\\Services');