@@ -19,35 +19,35 @@ class Comment
19
19
/**
20
20
* Splits a single doc block comment token up into something that can be easily iterated over.
21
21
*
22
- * @param string $string The doc block comment string to parse.
22
+ * @param string $comment The doc block comment string to parse.
23
23
* @param string $eolChar The EOL character to use for splitting strings.
24
24
* @param int $stackPtr The position of the token in the "new"/final token stream.
25
25
*
26
26
* @return array<int, array<string, string|int|array<int>>>
27
27
*/
28
- public function tokenizeString ($ string , $ eolChar , $ stackPtr )
28
+ public function tokenizeString ($ comment , $ eolChar , $ stackPtr )
29
29
{
30
30
if (PHP_CODESNIFFER_VERBOSITY > 1 ) {
31
31
StatusWriter::write ('*** START COMMENT TOKENIZING *** ' , 2 );
32
32
}
33
33
34
34
$ tokens = [];
35
- $ numChars = strlen ($ string );
35
+ $ numChars = strlen ($ comment );
36
36
37
37
/*
38
38
Doc block comments start with /*, but typically contain an
39
39
extra star when they are used for function and class comments.
40
40
*/
41
41
42
- $ char = ($ numChars - strlen (ltrim ($ string , '/* ' )));
43
- $ lastChars = substr ($ string , -2 );
42
+ $ char = ($ numChars - strlen (ltrim ($ comment , '/* ' )));
43
+ $ lastChars = substr ($ comment , -2 );
44
44
if ($ char === $ numChars && $ lastChars === '*/ ' ) {
45
45
// Edge case: docblock without whitespace or contents.
46
- $ openTag = substr ($ string , 0 , -2 );
47
- $ string = $ lastChars ;
46
+ $ openTag = substr ($ comment , 0 , -2 );
47
+ $ comment = $ lastChars ;
48
48
} else {
49
- $ openTag = substr ($ string , 0 , $ char );
50
- $ string = ltrim ($ string , '/* ' );
49
+ $ openTag = substr ($ comment , 0 , $ char );
50
+ $ comment = ltrim ($ comment , '/* ' );
51
51
}
52
52
53
53
$ tokens [$ stackPtr ] = [
@@ -73,7 +73,7 @@ public function tokenizeString($string, $eolChar, $stackPtr)
73
73
*/
74
74
75
75
$ closeTag = [
76
- 'content ' => substr ($ string , strlen (rtrim ($ string , '/* ' ))),
76
+ 'content ' => substr ($ comment , strlen (rtrim ($ comment , '/* ' ))),
77
77
'code ' => T_DOC_COMMENT_CLOSE_TAG ,
78
78
'type ' => 'T_DOC_COMMENT_CLOSE_TAG ' ,
79
79
'comment_opener ' => $ openPtr ,
@@ -84,7 +84,7 @@ public function tokenizeString($string, $eolChar, $stackPtr)
84
84
$ closeTag ['content ' ] = '' ;
85
85
}
86
86
87
- $ string = rtrim ($ string , '/* ' );
87
+ $ string = rtrim ($ comment , '/* ' );
88
88
89
89
/*
90
90
Process each line of the comment.
@@ -181,32 +181,32 @@ public function tokenizeString($string, $eolChar, $stackPtr)
181
181
/**
182
182
* Process a single line of a comment.
183
183
*
184
- * @param string $string The comment string being tokenized.
184
+ * @param string $comment The comment string being tokenized.
185
185
* @param string $eolChar The EOL character to use for splitting strings.
186
186
* @param int $start The position in the string to start processing.
187
187
* @param int $end The position in the string to end processing.
188
188
*
189
189
* @return array<int, array<string, string|int>>
190
190
*/
191
- private function processLine ($ string , $ eolChar , $ start , $ end )
191
+ private function processLine ($ comment , $ eolChar , $ start , $ end )
192
192
{
193
193
$ tokens = [];
194
194
195
195
// Collect content padding.
196
- $ space = $ this ->collectWhitespace ($ string , $ start , $ end );
196
+ $ space = $ this ->collectWhitespace ($ comment , $ start , $ end );
197
197
if ($ space !== null ) {
198
198
$ tokens [] = $ space ;
199
199
$ start += strlen ($ space ['content ' ]);
200
200
}
201
201
202
- if (isset ($ string [$ start ]) === false ) {
202
+ if (isset ($ comment [$ start ]) === false ) {
203
203
return $ tokens ;
204
204
}
205
205
206
- if ($ string [$ start ] === '@ ' ) {
206
+ if ($ comment [$ start ] === '@ ' ) {
207
207
// The content up until the first whitespace is the tag name.
208
208
$ matches = [];
209
- preg_match ('/@[^\s]+/ ' , $ string , $ matches , 0 , $ start );
209
+ preg_match ('/@[^\s]+/ ' , $ comment , $ matches , 0 , $ start );
210
210
if (isset ($ matches [0 ]) === true
211
211
&& substr (strtolower ($ matches [0 ]), 0 , 7 ) !== '@phpcs: '
212
212
) {
@@ -219,7 +219,7 @@ private function processLine($string, $eolChar, $start, $end)
219
219
];
220
220
221
221
// Then there will be some whitespace.
222
- $ space = $ this ->collectWhitespace ($ string , $ start , $ end );
222
+ $ space = $ this ->collectWhitespace ($ comment , $ start , $ end );
223
223
if ($ space !== null ) {
224
224
$ tokens [] = $ space ;
225
225
$ start += strlen ($ space ['content ' ]);
@@ -228,22 +228,22 @@ private function processLine($string, $eolChar, $start, $end)
228
228
}//end if
229
229
230
230
// Process the rest of the line.
231
- $ eol = strpos ($ string , $ eolChar , $ start );
231
+ $ eol = strpos ($ comment , $ eolChar , $ start );
232
232
if ($ eol === false ) {
233
233
$ eol = $ end ;
234
234
}
235
235
236
236
if ($ eol > $ start ) {
237
237
$ tokens [] = [
238
- 'content ' => substr ($ string , $ start , ($ eol - $ start )),
238
+ 'content ' => substr ($ comment , $ start , ($ eol - $ start )),
239
239
'code ' => T_DOC_COMMENT_STRING ,
240
240
'type ' => 'T_DOC_COMMENT_STRING ' ,
241
241
];
242
242
}
243
243
244
244
if ($ eol !== $ end ) {
245
245
$ tokens [] = [
246
- 'content ' => substr ($ string , $ eol , strlen ($ eolChar )),
246
+ 'content ' => substr ($ comment , $ eol , strlen ($ eolChar )),
247
247
'code ' => T_DOC_COMMENT_WHITESPACE ,
248
248
'type ' => 'T_DOC_COMMENT_WHITESPACE ' ,
249
249
];
@@ -257,21 +257,21 @@ private function processLine($string, $eolChar, $start, $end)
257
257
/**
258
258
* Collect consecutive whitespace into a single token.
259
259
*
260
- * @param string $string The comment string being tokenized.
261
- * @param int $start The position in the string to start processing.
262
- * @param int $end The position in the string to end processing.
260
+ * @param string $comment The comment string being tokenized.
261
+ * @param int $start The position in the string to start processing.
262
+ * @param int $end The position in the string to end processing.
263
263
*
264
264
* @return array<string, string|int>|null
265
265
*/
266
- private function collectWhitespace ($ string , $ start , $ end )
266
+ private function collectWhitespace ($ comment , $ start , $ end )
267
267
{
268
268
$ space = '' ;
269
269
for ($ start ; $ start < $ end ; $ start ++) {
270
- if ($ string [$ start ] !== ' ' && $ string [$ start ] !== "\t" ) {
270
+ if ($ comment [$ start ] !== ' ' && $ comment [$ start ] !== "\t" ) {
271
271
break ;
272
272
}
273
273
274
- $ space .= $ string [$ start ];
274
+ $ space .= $ comment [$ start ];
275
275
}
276
276
277
277
if ($ space === '' ) {
0 commit comments