@@ -46,14 +46,14 @@ final class Parser implements DictionaryParser, InnerListParser, ItemParser, Lis
46
46
47
47
public function parseValue (Stringable |string $ httpValue ): ByteSequence |Token |DateTimeImmutable |string |int |float |bool
48
48
{
49
- $ valueString = trim ((string ) $ httpValue , ' ' );
50
- if ('' === $ valueString || 1 === preg_match (self ::REGEXP_INVALID_CHARACTERS , $ valueString )) {
51
- throw new SyntaxError (' The HTTP textual representation " ' . $ httpValue. ' " for an item value contains invalid characters. ' );
49
+ $ remainder = trim ((string ) $ httpValue , ' ' );
50
+ if ('' === $ remainder || 1 === preg_match (self ::REGEXP_INVALID_CHARACTERS , $ remainder )) {
51
+ throw new SyntaxError (" The HTTP textual representation \" $ httpValue\ " for an item value contains invalid characters. " );
52
52
}
53
53
54
- [$ value , $ offset ] = self ::extractValue ($ valueString );
55
- if ('' !== substr ($ valueString , $ offset )) {
56
- throw new SyntaxError (' The HTTP textual representation " ' . $ httpValue. ' " for an item value contains invalid characters. ' );
54
+ [$ value , $ offset ] = self ::extractValue ($ remainder );
55
+ if ('' !== substr ($ remainder , $ offset )) {
56
+ throw new SyntaxError (" The HTTP textual representation \" $ httpValue\ " for an item value contains invalid characters. " );
57
57
}
58
58
59
59
return $ value ;
@@ -64,15 +64,15 @@ public function parseValue(Stringable|string $httpValue): ByteSequence|Token|Dat
64
64
*/
65
65
public function parseItem (Stringable |string $ httpValue ): array
66
66
{
67
- $ itemString = trim ((string ) $ httpValue , ' ' );
68
- if ('' === $ itemString || 1 === preg_match (self ::REGEXP_INVALID_CHARACTERS , $ itemString )) {
69
- throw new SyntaxError (' The HTTP textual representation " ' . $ httpValue. ' " for an item contains invalid characters. ' );
67
+ $ remainder = trim ((string ) $ httpValue , ' ' );
68
+ if ('' === $ remainder || 1 === preg_match (self ::REGEXP_INVALID_CHARACTERS , $ remainder )) {
69
+ throw new SyntaxError (" The HTTP textual representation \" $ httpValue\ " for an item contains invalid characters. " );
70
70
}
71
71
72
- [$ value , $ offset ] = self ::extractValue ($ itemString );
73
- $ remainder = substr ($ itemString , $ offset );
72
+ [$ value , $ offset ] = self ::extractValue ($ remainder );
73
+ $ remainder = substr ($ remainder , $ offset );
74
74
if ('' !== $ remainder && !str_contains ($ remainder , '; ' )) {
75
- throw new SyntaxError (' The HTTP textual representation " ' . $ httpValue. ' " for an item contains invalid characters. ' );
75
+ throw new SyntaxError (" The HTTP textual representation \" $ httpValue\ " for an item contains invalid characters. " );
76
76
}
77
77
78
78
return [$ value , $ this ->parseParameters ($ remainder )];
@@ -89,10 +89,10 @@ public function parseItem(Stringable|string $httpValue): array
89
89
*/
90
90
public function parseParameters (Stringable |string $ httpValue ): array
91
91
{
92
- $ parameterString = trim ((string ) $ httpValue );
93
- [$ parameters , $ offset ] = self ::extractParametersValues ($ parameterString );
94
- if (strlen ($ parameterString ) !== $ offset ) {
95
- throw new SyntaxError (' The HTTP textual representation " ' . $ httpValue. ' " for Parameters contains invalid characters. ' );
92
+ $ remainder = trim ((string ) $ httpValue );
93
+ [$ parameters , $ offset ] = self ::extractParametersValues ($ remainder );
94
+ if (strlen ($ remainder ) !== $ offset ) {
95
+ throw new SyntaxError (" The HTTP textual representation \" $ httpValue\ " for Parameters contains invalid characters. " );
96
96
}
97
97
98
98
return $ parameters ;
@@ -170,23 +170,23 @@ public function parseInnerList(Stringable|string $httpValue): array
170
170
*
171
171
* @see https://tools.ietf.org/html/rfc7230#section-3.2.3
172
172
*/
173
- private static function removeCommaSeparatedWhiteSpaces (string $ httpValue , int $ offset ): string
173
+ private static function removeCommaSeparatedWhiteSpaces (string $ remainder , int $ offset ): string
174
174
{
175
- $ httpValue = self ::removeOptionalWhiteSpaces (substr ($ httpValue , $ offset ));
176
- if ('' === $ httpValue ) {
177
- return $ httpValue ;
175
+ $ remainder = self ::removeOptionalWhiteSpaces (substr ($ remainder , $ offset ));
176
+ if ('' === $ remainder ) {
177
+ return '' ;
178
178
}
179
179
180
- if (1 !== preg_match (self ::REGEXP_VALID_SPACE , $ httpValue , $ found )) {
180
+ if (1 !== preg_match (self ::REGEXP_VALID_SPACE , $ remainder , $ found )) {
181
181
throw new SyntaxError ('The HTTP textual representation is missing an excepted comma. ' );
182
182
}
183
183
184
- $ httpValue = substr ($ httpValue , strlen ($ found ['space ' ]));
185
- if ('' === $ httpValue ) {
184
+ $ remainder = substr ($ remainder , strlen ($ found ['space ' ]));
185
+ if ('' === $ remainder ) {
186
186
throw new SyntaxError ('The HTTP textual representation has an unexpected end of line. ' );
187
187
}
188
188
189
- return $ httpValue ;
189
+ return $ remainder ;
190
190
}
191
191
192
192
/**
@@ -242,11 +242,11 @@ private static function extractInnerList(string $httpValue): array
242
242
[$ list [], $ remainder ] = self ::extractItem ($ remainder );
243
243
244
244
if ('' !== $ remainder && !in_array ($ remainder [0 ], [' ' , ') ' ], true )) {
245
- throw new SyntaxError ("The HTTP textual representation \"$ remainder \" for a inner list is using invalid characters. " );
245
+ throw new SyntaxError ("The HTTP textual representation \"$ httpValue \" for a inner list is using invalid characters. " );
246
246
}
247
247
}
248
248
249
- throw new SyntaxError ("The HTTP textual representation \"$ remainder \" for a inner list has an unexpected end of line. " );
249
+ throw new SyntaxError ("The HTTP textual representation \"$ httpValue \" for a inner list has an unexpected end of line. " );
250
250
}
251
251
252
252
/**
@@ -372,41 +372,40 @@ private static function extractDate(string $httpValue): array
372
372
private static function extractString (string $ httpValue ): array
373
373
{
374
374
$ offset = 1 ;
375
- $ originalHttpValue = $ httpValue ;
376
- $ httpValue = substr ($ httpValue , $ offset );
375
+ $ remainder = substr ($ httpValue , $ offset );
377
376
$ output = '' ;
378
377
379
- while ('' !== $ httpValue ) {
380
- $ char = $ httpValue [0 ];
378
+ while ('' !== $ remainder ) {
379
+ $ char = $ remainder [0 ];
381
380
$ offset += 1 ;
382
381
383
382
if ('" ' === $ char ) {
384
383
return [$ output , $ offset ];
385
384
}
386
385
387
386
if (1 === preg_match (self ::REGEXP_INVALID_CHARACTERS , $ char )) {
388
- throw new SyntaxError ("The HTTP textual representation \"$ originalHttpValue \" for a String contains an invalid end string. " );
387
+ throw new SyntaxError ("The HTTP textual representation \"$ httpValue \" for a String contains an invalid end string. " );
389
388
}
390
389
391
- $ httpValue = substr ($ httpValue , 1 );
390
+ $ remainder = substr ($ remainder , 1 );
392
391
393
392
if ('\\' !== $ char ) {
394
393
$ output .= $ char ;
395
394
continue ;
396
395
}
397
396
398
- $ char = $ httpValue [0 ] ?? '' ;
397
+ $ char = $ remainder [0 ] ?? '' ;
399
398
$ offset += 1 ;
400
- $ httpValue = substr ($ httpValue , 1 );
399
+ $ remainder = substr ($ remainder , 1 );
401
400
402
401
if (!in_array ($ char , ['" ' , '\\' ], true )) {
403
- throw new SyntaxError ("The HTTP textual representation \"$ originalHttpValue \" for a String contains an invalid end string. " );
402
+ throw new SyntaxError ("The HTTP textual representation \"$ httpValue \" for a String contains an invalid end string. " );
404
403
}
405
404
406
405
$ output .= $ char ;
407
406
}
408
407
409
- throw new SyntaxError ("The HTTP textual representation \"$ originalHttpValue \" for a String contains an invalid end string. " );
408
+ throw new SyntaxError ("The HTTP textual representation \"$ httpValue \" for a String contains an invalid end string. " );
410
409
}
411
410
412
411
/**
0 commit comments