@@ -82,60 +82,56 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
82
82
break ;
83
83
}
84
84
85
- if (isset (Tokens::$ commentTokens [$ tokens [$ prev ]['code ' ]]) === true ) {
85
+ if ($ tokens [$ prev ]['code ' ] === T_DOC_COMMENT_CLOSE_TAG ) {
86
+ $ start = $ prev ;
87
+ } else if (isset (Tokens::$ commentTokens [$ tokens [$ prev ]['code ' ]]) === true ) {
86
88
// Assume the comment belongs to the member var if it is on a line by itself.
87
89
$ prevContent = $ phpcsFile ->findPrevious (Tokens::$ emptyTokens , ($ prev - 1 ), null , true );
88
90
if ($ tokens [$ prevContent ]['line ' ] !== $ tokens [$ prev ]['line ' ]) {
89
- // Check the spacing, but then skip it.
90
- $ foundLines = ($ tokens [$ startOfStatement ]['line ' ] - $ tokens [$ prev ]['line ' ] - 1 );
91
- if ($ foundLines > 0 ) {
92
- for ($ i = ($ prev + 1 ); $ i < $ startOfStatement ; $ i ++) {
93
- if ($ tokens [$ i ]['column ' ] !== 1 ) {
94
- continue ;
95
- }
96
-
97
- if ($ tokens [$ i ]['code ' ] === T_WHITESPACE
98
- && $ tokens [$ i ]['line ' ] !== $ tokens [($ i + 1 )]['line ' ]
99
- ) {
100
- $ error = 'Expected 0 blank lines after member var comment; %s found ' ;
101
- $ data = [$ foundLines ];
102
- $ fix = $ phpcsFile ->addFixableError ($ error , $ prev , 'AfterComment ' , $ data );
103
- if ($ fix === true ) {
104
- $ phpcsFile ->fixer ->beginChangeset ();
105
- // Inline comments have the newline included in the content but
106
- // docblocks do not.
107
- if ($ tokens [$ prev ]['code ' ] === T_COMMENT ) {
108
- $ phpcsFile ->fixer ->replaceToken ($ prev , rtrim ($ tokens [$ prev ]['content ' ]));
109
- }
110
-
111
- for ($ i = ($ prev + 1 ); $ i <= $ startOfStatement ; $ i ++) {
112
- if ($ tokens [$ i ]['line ' ] === $ tokens [$ startOfStatement ]['line ' ]) {
113
- break ;
114
- }
115
-
116
- // Remove the newline after the docblock, and any entirely
117
- // empty lines before the member var.
118
- if (($ tokens [$ i ]['code ' ] === T_WHITESPACE
119
- && $ tokens [$ i ]['line ' ] === $ tokens [$ prev ]['line ' ])
120
- || ($ tokens [$ i ]['column ' ] === 1
121
- && $ tokens [$ i ]['line ' ] !== $ tokens [($ i + 1 )]['line ' ])
122
- ) {
123
- $ phpcsFile ->fixer ->replaceToken ($ i , '' );
124
- }
125
- }
126
-
127
- $ phpcsFile ->fixer ->addNewline ($ prev );
128
- $ phpcsFile ->fixer ->endChangeset ();
129
- }//end if
130
-
131
- break ;
132
- }//end if
133
- }//end for
134
- }//end if
135
-
136
91
$ start = $ prev ;
137
- }//end if
138
- }//end if
92
+ }
93
+ }
94
+
95
+ // Check for blank lines between the docblock/comment and the property declaration.
96
+ for ($ i = ($ start + 1 ); $ i < $ startOfStatement ; $ i ++) {
97
+ if (isset ($ tokens [$ i ]['attribute_closer ' ]) === true ) {
98
+ $ i = $ tokens [$ i ]['attribute_closer ' ];
99
+ continue ;
100
+ }
101
+
102
+ if ($ tokens [$ i ]['column ' ] !== 1
103
+ || $ tokens [$ i ]['code ' ] !== T_WHITESPACE
104
+ || $ tokens [$ i ]['line ' ] === $ tokens [($ i + 1 )]['line ' ]
105
+ // Do not report blank lines after a PHPCS annotation as removing the blank lines could change the meaning.
106
+ || isset (Tokens::$ phpcsCommentTokens [$ tokens [($ i - 1 )]['code ' ]]) === true
107
+ ) {
108
+ continue ;
109
+ }
110
+
111
+ // We found a blank line which should be reported.
112
+ $ nextNonWhitespace = $ phpcsFile ->findNext (T_WHITESPACE , ($ i + 1 ), null , true );
113
+ $ foundLines = ($ tokens [$ nextNonWhitespace ]['line ' ] - $ tokens [$ i ]['line ' ]);
114
+
115
+ $ error = 'Expected no blank lines between the member var comment and the declaration; %s found ' ;
116
+ $ data = [$ foundLines ];
117
+ $ fix = $ phpcsFile ->addFixableError ($ error , $ i , 'AfterComment ' , $ data );
118
+
119
+ if ($ fix === true ) {
120
+ $ phpcsFile ->fixer ->beginChangeset ();
121
+
122
+ for ($ j = $ i ; $ j < $ nextNonWhitespace ; $ j ++) {
123
+ if ($ tokens [$ j ]['line ' ] === $ tokens [$ nextNonWhitespace ]['line ' ]) {
124
+ break ;
125
+ }
126
+
127
+ $ phpcsFile ->fixer ->replaceToken ($ j , '' );
128
+ }
129
+
130
+ $ phpcsFile ->fixer ->endChangeset ();
131
+ }
132
+
133
+ $ i = $ nextNonWhitespace ;
134
+ }//end for
139
135
140
136
// There needs to be n blank lines before the var, not counting comments.
141
137
if ($ start === $ startOfStatement ) {
0 commit comments