File tree Expand file tree Collapse file tree 7 files changed +57
-2
lines changed Expand file tree Collapse file tree 7 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ private function getReformattedContents(array $nodes, int $level): string
108
108
*/
109
109
private function prepareReplacements (array $ nodes ): array
110
110
{
111
- $ start = $ nodes [0 ]-> getStartFilePos ( );
111
+ $ start = $ this -> getNodeStartPos ( $ nodes [0 ]);
112
112
$ replacements = [];
113
113
(new NodeFinder )->find ($ nodes , function (Node $ node ) use (&$ replacements , $ start ) {
114
114
if ($ node instanceof Node \Name \FullyQualified) {
@@ -430,7 +430,15 @@ private function toPhp(mixed $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
}
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ abstract class Class7
27
27
28
28
public function long()
29
29
{
30
+ // comment
30
31
if ($member instanceof Method) {
31
32
$s = [1, 2, 3];
32
33
}
@@ -39,6 +40,7 @@ abstract class Class7
39
40
40
41
public function resolving($a = Abc\a\FOO, self $b = null, $c = self::FOO)
41
42
{
43
+ // constants
42
44
echo FOO;
43
45
echo \FOO;
44
46
echo a\FOO;
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ abstract class Class7
37
37
38
38
function long()
39
39
{
40
+ // comment
40
41
if ($member instanceof Method) {
41
42
$s = [1, 2, 3];
42
43
}
@@ -49,6 +50,7 @@ abstract class Class7
49
50
50
51
function resolving($a = a\FOO, self $b = null, $c = self::FOO)
51
52
{
53
+ // constants
52
54
echo FOO;
53
55
echo \FOO;
54
56
echo a\FOO;
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ abstract class Class7
32
32
33
33
function long()
34
34
{
35
+ // comment
35
36
if ($member instanceof \Abc\Method) {
36
37
$s = [1, 2, 3];
37
38
}
@@ -44,6 +45,7 @@ abstract class Class7
44
45
45
46
function resolving($a = \Abc\a\FOO, self $b = null, $c = self::FOO)
46
47
{
48
+ // constants
47
49
echo FOO;
48
50
echo \FOO;
49
51
echo \Abc\a\FOO;
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ abstract class Class7
32
32
33
33
function long()
34
34
{
35
+ // comment
35
36
if ($member instanceof \Abc\Method) {
36
37
$s = [1, 2, 3];
37
38
}
@@ -44,6 +45,7 @@ abstract class Class7
44
45
45
46
function resolving($a = \Abc\a\FOO, self $b = null, $c = self::FOO)
46
47
{
48
+ // constants
47
49
echo FOO;
48
50
echo \FOO;
49
51
echo \Abc\a\FOO;
Original file line number Diff line number Diff line change @@ -9,6 +9,27 @@ class Class1
9
9
}
10
10
};
11
11
}
12
+
13
+
14
+ function comment1()
15
+ {
16
+ /** comment */
17
+ $a = 10;
18
+ }
19
+
20
+
21
+ function comment2()
22
+ {
23
+ // comment
24
+ "bar";
25
+ }
26
+
27
+
28
+ function comment3()
29
+ {
30
+ // comment
31
+ Foo\Bar::XX;
32
+ }
12
33
}
13
34
14
35
/**
Original file line number Diff line number Diff line change @@ -8,6 +8,24 @@ function bar() {
8
8
}
9
9
};
10
10
}
11
+
12
+ function comment1 ()
13
+ {
14
+ /** comment */
15
+ $ a = 10 ;
16
+ }
17
+
18
+ function comment2 ()
19
+ {
20
+ // comment
21
+ 'bar ' ;
22
+ }
23
+
24
+ function comment3 ()
25
+ {
26
+ // comment
27
+ Foo \Bar::XX ;
28
+ }
11
29
}
12
30
13
31
function () {};
You can’t perform that action at this time.
0 commit comments