@@ -89,19 +89,23 @@ public function register()
89
89
public function process (File $ phpcsFile , $ stackPtr )
90
90
{
91
91
$ tokens = $ phpcsFile ->getTokens ();
92
- $ find = Tokens::$ methodPrefixes ;
93
- $ find [] = T_WHITESPACE ;
92
+ $ ignore = Tokens::$ methodPrefixes ;
93
+ $ ignore [T_WHITESPACE ] = T_WHITESPACE ;
94
+ $ functionCodeStart = $ stackPtr ;
94
95
95
- $ beforeFunction = $ phpcsFile ->findPrevious ($ find , ($ stackPtr - 1 ), null , true );
96
- if ($ tokens [$ beforeFunction ]['code ' ] === T_ATTRIBUTE_END
97
- && $ tokens [$ tokens [$ beforeFunction ]['attribute_opener ' ]]['code ' ] === T_ATTRIBUTE
98
- ) {
99
- // It's an attribute, such as #[\ReturnTypeWillChange].
100
- $ attributeLines = ($ tokens [$ beforeFunction ]['line ' ] - $ tokens [$ tokens [$ beforeFunction ]['attribute_opener ' ]]['line ' ] + 1 );
101
- $ commentEnd = $ phpcsFile ->findPrevious ($ find , ($ tokens [$ beforeFunction ]['attribute_opener ' ] - 1 ), null , true );
102
- } else {
103
- $ attributeLines = 0 ;
104
- $ commentEnd = $ phpcsFile ->findPrevious ($ find , ($ stackPtr - 1 ), null , true );
96
+ for ($ commentEnd = ($ stackPtr - 1 ); $ commentEnd >= 0 ; $ commentEnd --) {
97
+ if (isset ($ ignore [$ tokens [$ commentEnd ]['code ' ]]) === true ) {
98
+ continue ;
99
+ }
100
+
101
+ if ($ tokens [$ commentEnd ]['code ' ] === T_ATTRIBUTE_END
102
+ && isset ($ tokens [$ commentEnd ]['attribute_opener ' ]) === true
103
+ ) {
104
+ $ commentEnd = $ functionCodeStart = $ tokens [$ commentEnd ]['attribute_opener ' ];
105
+ continue ;
106
+ }
107
+
108
+ break ;
105
109
}
106
110
107
111
$ beforeCommentEnd = $ phpcsFile ->findPrevious (Tokens::$ emptyTokens , ($ commentEnd - 1 ), null , true );
@@ -162,7 +166,7 @@ public function process(File $phpcsFile, $stackPtr)
162
166
}
163
167
}//end foreach
164
168
165
- if ($ tokens [$ commentEnd ]['line ' ] !== ($ tokens [$ stackPtr ]['line ' ] - $ attributeLines - 1 )) {
169
+ if ($ tokens [$ commentEnd ]['line ' ] !== ($ tokens [$ functionCodeStart ]['line ' ] - 1 )) {
166
170
$ error = 'There must be no blank lines after the function comment ' ;
167
171
$ fix = $ phpcsFile ->addFixableError ($ error , $ commentEnd , 'SpacingAfter ' );
168
172
if ($ fix === true ) {
0 commit comments