@@ -54,9 +54,24 @@ public function process(File $phpcsFile, $stackPtr)
54
54
55
55
$ tokens = $ phpcsFile ->getTokens ();
56
56
$ 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
+ }
58
74
59
- $ commentEnd = $ phpcsFile ->findPrevious ($ ignore , ($ stackPtr - 1 ), null , true );
60
75
if ($ tokens [$ commentEnd ]['code ' ] === T_COMMENT ) {
61
76
// Inline comments might just be closing comments for
62
77
// control structures or functions instead of function comments
@@ -102,8 +117,20 @@ public function process(File $phpcsFile, $stackPtr)
102
117
}
103
118
104
119
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
+ }
107
134
}
108
135
109
136
$ commentStart = $ tokens [$ commentEnd ]['comment_opener ' ];
0 commit comments