@@ -55,12 +55,24 @@ public static function getConsecutiveSingleLineComments( File $phpcsFile, $stack
55
55
return ;
56
56
}
57
57
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.
59
65
$ 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
+ }
64
76
}
65
77
}
66
78
@@ -69,9 +81,16 @@ public static function getConsecutiveSingleLineComments( File $phpcsFile, $stack
69
81
$ nextComment = $ stackPtr ;
70
82
while ( true ) {
71
83
$ 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 ) ) {
73
85
break ; // The block has ended.
74
86
}
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
+
75
94
$ lineCount ++;
76
95
}
77
96
0 commit comments