@@ -31,6 +31,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
3131 $ previousType = '' ;
3232 foreach ($ tokens [$ stackPtr ]['comment_tags ' ] as $ commentTag ) {
3333 $ currentType = $ tokens [$ commentTag ]['content ' ];
34+ $ commentTagLine = $ tokens [$ commentTag ]['line ' ];
3435
3536 $ previousString = $ phpcsFile ->findPrevious (
3637 T_DOC_COMMENT_STRING ,
@@ -40,10 +41,15 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
4041
4142 if (false !== $ previousString ) {
4243 $ 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+ }
4450
4551 if ($ previousType === $ currentType ) {
46- if ($ previousStringLine !== $ commentTagLine - 1 ) {
52+ if ($ previousLine !== $ commentTagLine - 1 ) {
4753 $ fix = $ phpcsFile ->addFixableError (
4854 'Expected no empty lines '
4955 . 'between annotations of the same type ' ,
@@ -56,14 +62,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
5662 $ this ->removeLines (
5763 $ phpcsFile ,
5864 $ previousString ,
59- $ previousStringLine + 1 ,
65+ $ previousLine + 1 ,
6066 $ commentTagLine - 1
6167 );
6268 $ phpcsFile ->fixer ->endChangeset ();
6369 }
6470 }
6571 } else {
66- if ($ previousStringLine !== $ commentTagLine - 2 ) {
72+ if ($ previousLine !== $ commentTagLine - 2 ) {
6773 $ fix = $ phpcsFile ->addFixableError (
6874 'Expected exactly one empty line '
6975 . 'between annotations of different types ' ,
@@ -73,7 +79,8 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
7379
7480 if ($ fix === true ) {
7581 $ phpcsFile ->fixer ->beginChangeset ();
76- if ($ previousStringLine === $ commentTagLine - 1 ) {
82+
83+ if ($ previousLine === $ commentTagLine - 1 ) {
7784 $ firstOnLine = $ phpcsFile ->findFirstOnLine (
7885 array (),
7986 $ commentTag ,
@@ -95,7 +102,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
95102 $ this ->removeLines (
96103 $ phpcsFile ,
97104 $ previousString ,
98- $ previousStringLine + 2 ,
105+ $ previousLine + 2 ,
99106 $ commentTagLine - 1
100107 );
101108 }
@@ -106,6 +113,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
106113 }
107114
108115 $ previousType = $ currentType ;
116+ $ previousTagLine = $ commentTagLine ;
109117 }
110118 }
111119
0 commit comments