@@ -99,7 +99,7 @@ private function getReformattedContents(array $statements, int $level): string
99
99
100
100
private function prepareReplacements (array $ statements ): array
101
101
{
102
- $ start = $ statements [0 ]-> getStartFilePos ( );
102
+ $ start = $ this -> getNodeStartPos ( $ statements [0 ]);
103
103
$ replacements = [];
104
104
(new NodeFinder )->find ($ statements , function (Node $ node ) use (&$ replacements , $ start ) {
105
105
if ($ node instanceof Node \Name \FullyQualified) {
@@ -430,7 +430,15 @@ private function toPhp($value): string
430
430
431
431
private function getNodeContents (Node ...$ nodes ): string
432
432
{
433
- $ start = $ nodes [0 ]-> getStartFilePos ( );
433
+ $ start = $ this -> getNodeStartPos ( $ nodes [0 ]);
434
434
return substr ($ this ->code , $ start , end ($ nodes )->getEndFilePos () - $ start + 1 );
435
435
}
436
+
437
+
438
+ private function getNodeStartPos (Node $ node ): int
439
+ {
440
+ return ($ comments = $ node ->getComments ())
441
+ ? $ comments [0 ]->getStartFilePos ()
442
+ : $ node ->getStartFilePos ();
443
+ }
436
444
}
0 commit comments