@@ -54,9 +54,24 @@ public function process(File $phpcsFile, $stackPtr)
5454
5555 $ tokens = $ phpcsFile ->getTokens ();
5656 $ ignore = Tokens::$ methodPrefixes ;
57- $ ignore [] = T_WHITESPACE ;
57+ $ ignore [T_WHITESPACE ] = T_WHITESPACE ;
58+
59+ for ($ commentEnd = ($ stackPtr - 1 ); $ commentEnd >= 0 ; $ commentEnd --) {
60+ if (isset ($ ignore [$ tokens [$ commentEnd ]['code ' ]]) === true ) {
61+ continue ;
62+ }
63+
64+ if (
65+ $ tokens [$ commentEnd ]['code ' ] === T_ATTRIBUTE_END
66+ && isset ($ tokens [$ commentEnd ]['attribute_opener ' ]) === true
67+ ) {
68+ $ commentEnd = $ tokens [$ commentEnd ]['attribute_opener ' ];
69+ continue ;
70+ }
71+
72+ break ;
73+ }
5874
59- $ commentEnd = $ phpcsFile ->findPrevious ($ ignore , ($ stackPtr - 1 ), null , true );
6075 if ($ tokens [$ commentEnd ]['code ' ] === T_COMMENT ) {
6176 // Inline comments might just be closing comments for
6277 // control structures or functions instead of function comments
@@ -102,8 +117,20 @@ public function process(File $phpcsFile, $stackPtr)
102117 }
103118
104119 if ($ tokens [$ commentEnd ]['line ' ] !== ($ tokens [$ stackPtr ]['line ' ] - 1 )) {
105- $ error = 'There must be no blank lines after the function comment ' ;
106- $ phpcsFile ->addError ($ error , $ commentEnd , 'SpacingAfter ' );
120+ for ($ i = ($ commentEnd + 1 ); $ i < $ stackPtr ; $ i ++) {
121+ if ($ tokens [$ i ]['column ' ] !== 1 ) {
122+ continue ;
123+ }
124+
125+ if (
126+ $ tokens [$ i ]['code ' ] === T_WHITESPACE
127+ && $ tokens [$ i ]['line ' ] !== $ tokens [($ i + 1 )]['line ' ]
128+ ) {
129+ $ error = 'There must be no blank lines after the function comment ' ;
130+ $ phpcsFile ->addError ($ error , $ commentEnd , 'SpacingAfter ' );
131+ break ;
132+ }
133+ }
107134 }
108135
109136 $ commentStart = $ tokens [$ commentEnd ]['comment_opener ' ];
0 commit comments