@@ -31,6 +31,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
31
31
$ previousType = '' ;
32
32
foreach ($ tokens [$ stackPtr ]['comment_tags ' ] as $ commentTag ) {
33
33
$ currentType = $ tokens [$ commentTag ]['content ' ];
34
+ $ commentTagLine = $ tokens [$ commentTag ]['line ' ];
34
35
35
36
$ previousString = $ phpcsFile ->findPrevious (
36
37
T_DOC_COMMENT_STRING ,
@@ -40,10 +41,15 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
40
41
41
42
if (false !== $ previousString ) {
42
43
$ previousStringLine = $ tokens [$ previousString ]['line ' ];
43
- $ commentTagLine = $ tokens [$ commentTag ]['line ' ];
44
+
45
+ if (isset ($ previousTagLine )) {
46
+ $ previousLine = max ($ previousStringLine , $ previousTagLine );
47
+ } else {
48
+ $ previousLine = $ previousStringLine ;
49
+ }
44
50
45
51
if ($ previousType === $ currentType ) {
46
- if ($ previousStringLine !== $ commentTagLine - 1 ) {
52
+ if ($ previousLine !== $ commentTagLine - 1 ) {
47
53
$ fix = $ phpcsFile ->addFixableError (
48
54
'Expected no empty lines '
49
55
. 'between annotations of the same type ' ,
@@ -56,14 +62,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
62
$ this ->removeLines (
57
63
$ phpcsFile ,
58
64
$ previousString ,
59
- $ previousStringLine + 1 ,
65
+ $ previousLine + 1 ,
60
66
$ commentTagLine - 1
61
67
);
62
68
$ phpcsFile ->fixer ->endChangeset ();
63
69
}
64
70
}
65
71
} else {
66
- if ($ previousStringLine !== $ commentTagLine - 2 ) {
72
+ if ($ previousLine !== $ commentTagLine - 2 ) {
67
73
$ fix = $ phpcsFile ->addFixableError (
68
74
'Expected exactly one empty line '
69
75
. 'between annotations of different types ' ,
@@ -73,7 +79,8 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
73
79
74
80
if ($ fix === true ) {
75
81
$ phpcsFile ->fixer ->beginChangeset ();
76
- if ($ previousStringLine === $ commentTagLine - 1 ) {
82
+
83
+ if ($ previousLine === $ commentTagLine - 1 ) {
77
84
$ firstOnLine = $ phpcsFile ->findFirstOnLine (
78
85
array (),
79
86
$ commentTag ,
@@ -95,7 +102,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
95
102
$ this ->removeLines (
96
103
$ phpcsFile ,
97
104
$ previousString ,
98
- $ previousStringLine + 2 ,
105
+ $ previousLine + 2 ,
99
106
$ commentTagLine - 1
100
107
);
101
108
}
@@ -106,6 +113,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
106
113
}
107
114
108
115
$ previousType = $ currentType ;
116
+ $ previousTagLine = $ commentTagLine ;
109
117
}
110
118
}
111
119
0 commit comments