File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 99use PhpParser \NodeVisitor \CloningVisitor ;
1010use PhpParser \Parser ;
1111use PHPStan \File \FileReader ;
12+ use PHPStan \Fixable \PhpPrinter ;
1213use PHPStan \Fixable \PhpPrinterIndentationDetectorVisitor ;
1314use PHPStan \Fixable \ReplacingNodeVisitor ;
14- use PHPStan \Node \Printer \Printer ;
1515use PHPStan \Node \VirtualNode ;
1616use PHPStan \Rules \FileRuleError ;
1717use 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments