@@ -55,12 +55,24 @@ public static function getConsecutiveSingleLineComments( File $phpcsFile, $stack
5555 return ;
5656 }
5757
58- // Check the previous line to see if we are already in a block.
58+ // If the comment is not on a line by itself, it's not part of a multi-line comment block.
59+ $ prev = $ phpcsFile ->findPrevious ( T_WHITESPACE , $ stackPtr - 1 , null , true );
60+ if ( false !== $ prev && $ tokens [ $ prev ]['line ' ] === $ token ['line ' ] ) {
61+ return ;
62+ }
63+
64+ // Check the previous line to see if we are already in a block of non-inline comments.
5965 $ prevLine = $ token ['line ' ] - 1 ;
60- $ prevComment = $ phpcsFile ->findPrevious ( T_COMMENT , $ stackPtr - 1 , null , false , null , true );
61- if ( false !== $ prevComment && $ tokens [$ prevComment ]['line ' ] === $ prevLine ) {
62- if ( '// ' === substr ( $ tokens [$ prevComment ]['content ' ], 0 , 2 ) ) {
63- return ; // This is not the start of the block.
66+ $ prevCommentPtr = $ phpcsFile ->findPrevious ( T_COMMENT , $ stackPtr - 1 , null , false , null , true );
67+ if ( false !== $ prevCommentPtr && $ tokens [ $ prevCommentPtr ]['line ' ] === $ prevLine ) {
68+ $ prevCommentToken = $ tokens [ $ prevCommentPtr ];
69+ if ( '// ' === substr ( $ prevCommentToken ['content ' ], 0 , 2 ) ) {
70+ // Was the previous comment also a non-inline comment?
71+ $ prev = $ phpcsFile ->findPrevious ( T_WHITESPACE , $ prevCommentPtr - 1 , null , true );
72+ if ( false === $ prev || $ tokens [ $ prev ]['line ' ] !== $ prevCommentToken ['line ' ] ) {
73+ // Yes, it was. So we are in the middle of a block.
74+ return ;
75+ }
6476 }
6577 }
6678
@@ -69,9 +81,16 @@ public static function getConsecutiveSingleLineComments( File $phpcsFile, $stack
6981 $ nextComment = $ stackPtr ;
7082 while ( true ) {
7183 $ nextComment = $ phpcsFile ->findNext ( T_COMMENT , $ nextComment + 1 , null , false , null , true );
72- if ( false === $ nextComment || $ tokens [$ nextComment ]['line ' ] !== ( $ token ['line ' ] + $ lineCount ) ) {
84+ if ( false === $ nextComment || $ tokens [ $ nextComment ]['line ' ] !== ( $ token ['line ' ] + $ lineCount ) ) {
7385 break ; // The block has ended.
7486 }
87+
88+ // If the next comment is not on a line by itself, it's an inline comment, so the block ends here.
89+ $ prev = $ phpcsFile ->findPrevious ( T_WHITESPACE , $ nextComment - 1 , null , true );
90+ if ( false !== $ prev && $ tokens [ $ prev ]['line ' ] === $ tokens [ $ nextComment ]['line ' ] ) {
91+ break ;
92+ }
93+
7594 $ lineCount ++;
7695 }
7796
0 commit comments