File tree 2 files changed +37
-2
lines changed 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 9
9
use PhpParser \NodeVisitor \CloningVisitor ;
10
10
use PhpParser \Parser ;
11
11
use PHPStan \File \FileReader ;
12
+ use PHPStan \Fixable \PhpPrinter ;
12
13
use PHPStan \Fixable \PhpPrinterIndentationDetectorVisitor ;
13
14
use PHPStan \Fixable \ReplacingNodeVisitor ;
14
- use PHPStan \Node \Printer \Printer ;
15
15
use PHPStan \Node \VirtualNode ;
16
16
use PHPStan \Rules \FileRuleError ;
17
17
use PHPStan \Rules \FixableNodeRuleError ;
@@ -126,7 +126,7 @@ public function transform(
126
126
/** @var Stmt[] $newStmts */
127
127
$ newStmts = $ traverser ->traverse ($ newStmts );
128
128
129
- $ printer = new Printer (['indent ' => str_repeat ($ indentDetector ->indentCharacter , $ indentDetector ->indentSize )]);
129
+ $ printer = new PhpPrinter (['indent ' => str_repeat ($ indentDetector ->indentCharacter , $ indentDetector ->indentSize )]);
130
130
$ newCode = $ printer ->printFormatPreserving ($ newStmts , $ fileNodes , $ oldTokens );
131
131
$ differ = new Differ ();
132
132
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