@@ -33,7 +33,7 @@ class ParserState
33
33
private $ characters ;
34
34
35
35
/**
36
- * @var int
36
+ * @var int<0, max>
37
37
*/
38
38
private $ currentPosition = 0 ;
39
39
@@ -53,7 +53,7 @@ class ParserState
53
53
* @param string $text the complete CSS as text (i.e., usually the contents of a CSS file)
54
54
* @param int<1, max> $lineNumber
55
55
*/
56
- public function __construct ($ text , Settings $ parserSettings , int $ lineNumber = 1 )
56
+ public function __construct (string $ text , Settings $ parserSettings , int $ lineNumber = 1 )
57
57
{
58
58
$ this ->parserSettings = $ parserSettings ;
59
59
$ this ->text = $ text ;
@@ -75,23 +75,20 @@ public function setCharset(string $charset): void
75
75
/**
76
76
* @return int<1, max>
77
77
*/
78
- public function currentLine ()
78
+ public function currentLine (): int
79
79
{
80
80
return $ this ->lineNumber ;
81
81
}
82
82
83
83
/**
84
- * @return int
84
+ * @return int<0, max>
85
85
*/
86
- public function currentColumn ()
86
+ public function currentColumn (): int
87
87
{
88
88
return $ this ->currentPosition ;
89
89
}
90
90
91
- /**
92
- * @return Settings
93
- */
94
- public function getSettings ()
91
+ public function getSettings (): Settings
95
92
{
96
93
return $ this ->parserSettings ;
97
94
}
@@ -102,21 +99,17 @@ public function anchor(): Anchor
102
99
}
103
100
104
101
/**
105
- * @param int $position
102
+ * @param int<0, max> $position
106
103
*/
107
- public function setPosition ($ position ): void
104
+ public function setPosition (int $ position ): void
108
105
{
109
106
$ this ->currentPosition = $ position ;
110
107
}
111
108
112
109
/**
113
- * @param bool $ignoreCase
114
- *
115
- * @return string
116
- *
117
110
* @throws UnexpectedTokenException
118
111
*/
119
- public function parseIdentifier ($ ignoreCase = true )
112
+ public function parseIdentifier (bool $ ignoreCase = true ): string
120
113
{
121
114
if ($ this ->isEnd ()) {
122
115
throw new UnexpectedEOFException ('' , '' , 'identifier ' , $ this ->lineNumber );
@@ -140,14 +133,10 @@ public function parseIdentifier($ignoreCase = true)
140
133
}
141
134
142
135
/**
143
- * @param bool $isForIdentifier
144
- *
145
- * @return string|null
146
- *
147
136
* @throws UnexpectedEOFException
148
137
* @throws UnexpectedTokenException
149
138
*/
150
- public function parseCharacter ($ isForIdentifier )
139
+ public function parseCharacter (bool $ isForIdentifier ): ? string
151
140
{
152
141
if ($ this ->peek () === '\\' ) {
153
142
$ this ->consume ('\\' );
@@ -225,11 +214,7 @@ public function consumeWhiteSpace(): array
225
214
return $ comments ;
226
215
}
227
216
228
- /**
229
- * @param string $string
230
- * @param bool $caseInsensitive
231
- */
232
- public function comes ($ string , $ caseInsensitive = false ): bool
217
+ public function comes (string $ string , bool $ caseInsensitive = false ): bool
233
218
{
234
219
$ peek = $ this ->peek (\strlen ($ string ));
235
220
return ($ peek == '' )
@@ -238,10 +223,10 @@ public function comes($string, $caseInsensitive = false): bool
238
223
}
239
224
240
225
/**
241
- * @param int $length
242
- * @param int $offset
226
+ * @param int<1, max> $length
227
+ * @param int<0, max> $offset
243
228
*/
244
- public function peek ($ length = 1 , $ offset = 0 ): string
229
+ public function peek (int $ length = 1 , int $ offset = 0 ): string
245
230
{
246
231
$ offset += $ this ->currentPosition ;
247
232
if ($ offset >= \count ($ this ->characters )) {
@@ -251,7 +236,7 @@ public function peek($length = 1, $offset = 0): string
251
236
}
252
237
253
238
/**
254
- * @param int $value
239
+ * @param string| int<1, max> $value
255
240
*
256
241
* @throws UnexpectedEOFException
257
242
* @throws UnexpectedTokenException
@@ -286,12 +271,12 @@ public function consume($value = 1): string
286
271
287
272
/**
288
273
* @param string $expression
289
- * @param int|null $maximumLength
274
+ * @param int<1, max> |null $maximumLength
290
275
*
291
276
* @throws UnexpectedEOFException
292
277
* @throws UnexpectedTokenException
293
278
*/
294
- public function consumeExpression ($ expression , $ maximumLength = null ): string
279
+ public function consumeExpression (string $ expression , ? int $ maximumLength = null ): string
295
280
{
296
281
$ matches = null ;
297
282
$ input = $ maximumLength !== null ? $ this ->peek ($ maximumLength ) : $ this ->inputLeft ();
@@ -335,17 +320,15 @@ public function isEnd(): bool
335
320
336
321
/**
337
322
* @param array<array-key, string>|string $stopCharacters
338
- * @param bool $includeEnd
339
- * @param bool $consumeEnd
340
323
* @param array<int, Comment> $comments
341
324
*
342
325
* @throws UnexpectedEOFException
343
326
* @throws UnexpectedTokenException
344
327
*/
345
328
public function consumeUntil (
346
329
$ stopCharacters ,
347
- $ includeEnd = false ,
348
- $ consumeEnd = false ,
330
+ bool $ includeEnd = false ,
331
+ bool $ consumeEnd = false ,
349
332
array &$ comments = []
350
333
): string {
351
334
$ stopCharacters = \is_array ($ stopCharacters ) ? $ stopCharacters : [$ stopCharacters ];
@@ -386,12 +369,7 @@ private function inputLeft(): string
386
369
return $ this ->substr ($ this ->currentPosition , -1 );
387
370
}
388
371
389
- /**
390
- * @param string $string1
391
- * @param string $string2
392
- * @param bool $caseInsensitive
393
- */
394
- public function streql ($ string1 , $ string2 , $ caseInsensitive = true ): bool
372
+ public function streql (string $ string1 , string $ string2 , bool $ caseInsensitive = true ): bool
395
373
{
396
374
if ($ caseInsensitive ) {
397
375
return $ this ->strtolower ($ string1 ) === $ this ->strtolower ($ string2 );
@@ -401,17 +379,17 @@ public function streql($string1, $string2, $caseInsensitive = true): bool
401
379
}
402
380
403
381
/**
404
- * @param int $numberOfCharacters
382
+ * @param int<1, max> $numberOfCharacters
405
383
*/
406
- public function backtrack ($ numberOfCharacters ): void
384
+ public function backtrack (int $ numberOfCharacters ): void
407
385
{
408
386
$ this ->currentPosition -= $ numberOfCharacters ;
409
387
}
410
388
411
389
/**
412
- * @param string $string
390
+ * @return int<0, max>
413
391
*/
414
- public function strlen ($ string ): int
392
+ public function strlen (string $ string ): int
415
393
{
416
394
if ($ this ->parserSettings ->hasMultibyteSupport ()) {
417
395
return \mb_strlen ($ string , $ this ->charset );
@@ -421,10 +399,9 @@ public function strlen($string): int
421
399
}
422
400
423
401
/**
424
- * @param int $offset
425
- * @param int $length
402
+ * @param int<0, max> $offset
426
403
*/
427
- private function substr ($ offset , $ length ): string
404
+ private function substr (int $ offset , int $ length ): string
428
405
{
429
406
if ($ length < 0 ) {
430
407
$ length = \count ($ this ->characters ) - $ offset + $ length ;
@@ -441,10 +418,7 @@ private function substr($offset, $length): string
441
418
return $ result ;
442
419
}
443
420
444
- /**
445
- * @param string $string
446
- */
447
- private function strtolower ($ string ): string
421
+ private function strtolower (string $ string ): string
448
422
{
449
423
if ($ this ->parserSettings ->hasMultibyteSupport ()) {
450
424
return \mb_strtolower ($ string , $ this ->charset );
@@ -454,13 +428,11 @@ private function strtolower($string): string
454
428
}
455
429
456
430
/**
457
- * @param string $string
458
- *
459
431
* @return array<int, string>
460
432
*
461
433
* @throws SourceException if the charset is UTF-8 and the string contains invalid byte sequences
462
434
*/
463
- private function strsplit ($ string )
435
+ private function strsplit (string $ string ): array
464
436
{
465
437
if ($ this ->parserSettings ->hasMultibyteSupport ()) {
466
438
if ($ this ->streql ($ this ->charset , 'utf-8 ' )) {
@@ -487,13 +459,9 @@ private function strsplit($string)
487
459
}
488
460
489
461
/**
490
- * @param string $haystack
491
- * @param string $needle
492
- * @param int $offset
493
- *
494
462
* @return int|false
495
463
*/
496
- private function strpos ($ haystack , $ needle , $ offset )
464
+ private function strpos (string $ haystack , string $ needle , int $ offset )
497
465
{
498
466
if ($ this ->parserSettings ->hasMultibyteSupport ()) {
499
467
return \mb_strpos ($ haystack , $ needle , $ offset , $ this ->charset );
0 commit comments