@@ -55,40 +55,74 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
5555
5656 $ endOfStatement = $ phpcsFile ->findNext (T_SEMICOLON , ($ stackPtr + 1 ), null , false , null , true );
5757
58- $ ignore = $ validPrefixes ;
59- $ ignore [] = T_WHITESPACE ;
58+ $ ignore = $ validPrefixes ;
59+ $ ignore [T_WHITESPACE ] = T_WHITESPACE ;
6060
6161 $ start = $ startOfStatement ;
62- $ prev = $ phpcsFile ->findPrevious ($ ignore , ($ startOfStatement - 1 ), null , true );
62+ for ($ prev = ($ startOfStatement - 1 ); $ prev >= 0 ; $ prev --) {
63+ if (isset ($ ignore [$ tokens [$ prev ]['code ' ]]) === true ) {
64+ continue ;
65+ }
66+
67+ if ($ tokens [$ prev ]['code ' ] === T_ATTRIBUTE_END
68+ && isset ($ tokens [$ prev ]['attribute_opener ' ]) === true
69+ ) {
70+ $ prev = $ tokens [$ prev ]['attribute_opener ' ];
71+ continue ;
72+ }
73+
74+ break ;
75+ }
76+
6377 if (isset (Tokens::$ commentTokens [$ tokens [$ prev ]['code ' ]]) === true ) {
6478 // Assume the comment belongs to the member var if it is on a line by itself.
6579 $ prevContent = $ phpcsFile ->findPrevious (Tokens::$ emptyTokens , ($ prev - 1 ), null , true );
6680 if ($ tokens [$ prevContent ]['line ' ] !== $ tokens [$ prev ]['line ' ]) {
6781 // Check the spacing, but then skip it.
6882 $ foundLines = ($ tokens [$ startOfStatement ]['line ' ] - $ tokens [$ prev ]['line ' ] - 1 );
6983 if ($ foundLines > 0 ) {
70- $ error = 'Expected 0 blank lines after member var comment; %s found ' ;
71- $ data = [$ foundLines ];
72- $ fix = $ phpcsFile ->addFixableError ($ error , $ prev , 'AfterComment ' , $ data );
73- if ($ fix === true ) {
74- $ phpcsFile ->fixer ->beginChangeset ();
75- // Inline comments have the newline included in the content but
76- // docblock do not.
77- if ($ tokens [$ prev ]['code ' ] === T_COMMENT ) {
78- $ phpcsFile ->fixer ->replaceToken ($ prev , rtrim ($ tokens [$ prev ]['content ' ]));
84+ for ($ i = ($ prev + 1 ); $ i < $ startOfStatement ; $ i ++) {
85+ if ($ tokens [$ i ]['column ' ] !== 1 ) {
86+ continue ;
7987 }
8088
81- for ($ i = ($ prev + 1 ); $ i <= $ startOfStatement ; $ i ++) {
82- if ($ tokens [$ i ]['line ' ] === $ tokens [$ startOfStatement ]['line ' ]) {
83- break ;
84- }
85-
86- $ phpcsFile ->fixer ->replaceToken ($ i , '' );
87- }
88-
89- $ phpcsFile ->fixer ->addNewline ($ prev );
90- $ phpcsFile ->fixer ->endChangeset ();
91- }
89+ if ($ tokens [$ i ]['code ' ] === T_WHITESPACE
90+ && $ tokens [$ i ]['line ' ] !== $ tokens [($ i + 1 )]['line ' ]
91+ ) {
92+ $ error = 'Expected 0 blank lines after member var comment; %s found ' ;
93+ $ data = [$ foundLines ];
94+ $ fix = $ phpcsFile ->addFixableError ($ error , $ prev , 'AfterComment ' , $ data );
95+ if ($ fix === true ) {
96+ $ phpcsFile ->fixer ->beginChangeset ();
97+ // Inline comments have the newline included in the content but
98+ // docblocks do not.
99+ if ($ tokens [$ prev ]['code ' ] === T_COMMENT ) {
100+ $ phpcsFile ->fixer ->replaceToken ($ prev , rtrim ($ tokens [$ prev ]['content ' ]));
101+ }
102+
103+ for ($ i = ($ prev + 1 ); $ i <= $ startOfStatement ; $ i ++) {
104+ if ($ tokens [$ i ]['line ' ] === $ tokens [$ startOfStatement ]['line ' ]) {
105+ break ;
106+ }
107+
108+ // Remove the newline after the docblock, and any entirely
109+ // empty lines before the member var.
110+ if ($ tokens [$ i ]['code ' ] === T_WHITESPACE
111+ && $ tokens [$ i ]['line ' ] === $ tokens [$ prev ]['line ' ]
112+ || ($ tokens [$ i ]['column ' ] === 1
113+ && $ tokens [$ i ]['line ' ] !== $ tokens [($ i + 1 )]['line ' ])
114+ ) {
115+ $ phpcsFile ->fixer ->replaceToken ($ i , '' );
116+ }
117+ }
118+
119+ $ phpcsFile ->fixer ->addNewline ($ prev );
120+ $ phpcsFile ->fixer ->endChangeset ();
121+ }//end if
122+
123+ break ;
124+ }//end if
125+ }//end for
92126 }//end if
93127
94128 $ start = $ prev ;
0 commit comments