Skip to content

Commit 6680175

Browse files
committed
Fix
1 parent a079fec commit 6680175

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/Analyser/RuleErrorTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use PhpParser\NodeVisitor\CloningVisitor;
1010
use PhpParser\Parser;
1111
use PHPStan\File\FileReader;
12+
use PHPStan\Fixable\PhpPrinter;
1213
use PHPStan\Fixable\PhpPrinterIndentationDetectorVisitor;
1314
use PHPStan\Fixable\ReplacingNodeVisitor;
14-
use PHPStan\Node\Printer\Printer;
1515
use PHPStan\Node\VirtualNode;
1616
use PHPStan\Rules\FileRuleError;
1717
use PHPStan\Rules\FixableNodeRuleError;
@@ -126,7 +126,7 @@ public function transform(
126126
/** @var Stmt[] $newStmts */
127127
$newStmts = $traverser->traverse($newStmts);
128128

129-
$printer = new Printer(['indent' => str_repeat($indentDetector->indentCharacter, $indentDetector->indentSize)]);
129+
$printer = new PhpPrinter(['indent' => str_repeat($indentDetector->indentCharacter, $indentDetector->indentSize)]);
130130
$newCode = $printer->printFormatPreserving($newStmts, $fileNodes, $oldTokens);
131131
$differ = new Differ();
132132

src/Fixable/PhpPrinter.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Fixable;
4+
5+
use PhpParser\Node;
6+
use PhpParser\PrettyPrinter\Standard;
7+
use function count;
8+
use function rtrim;
9+
10+
final class PhpPrinter extends Standard
11+
{
12+
13+
public const TAB_WIDTH = 4;
14+
public const FUNC_ARGS_TRAILING_COMMA_ATTRIBUTE = 'trailing_comma';
15+
16+
/**
17+
* @param Node[] $nodes
18+
*/
19+
protected function pCommaSeparated(array $nodes): string
20+
{
21+
$result = parent::pCommaSeparated($nodes);
22+
if (count($nodes) === 0) {
23+
return $result;
24+
}
25+
$last = $nodes[count($nodes) - 1];
26+
27+
$trailingComma = $last->getAttribute(self::FUNC_ARGS_TRAILING_COMMA_ATTRIBUTE);
28+
if ($trailingComma === false) {
29+
$result = rtrim($result, ',');
30+
}
31+
32+
return $result;
33+
}
34+
35+
}

0 commit comments

Comments
 (0)