@@ -46,14 +46,14 @@ final class Parser implements DictionaryParser, InnerListParser, ItemParser, Lis
4646
4747 public function parseValue (Stringable |string $ httpValue ): ByteSequence |Token |DateTimeImmutable |string |int |float |bool
4848 {
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. " );
5252 }
5353
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. " );
5757 }
5858
5959 return $ value ;
@@ -64,15 +64,15 @@ public function parseValue(Stringable|string $httpValue): ByteSequence|Token|Dat
6464 */
6565 public function parseItem (Stringable |string $ httpValue ): array
6666 {
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. " );
7070 }
7171
72- [$ value , $ offset ] = self ::extractValue ($ itemString );
73- $ remainder = substr ($ itemString , $ offset );
72+ [$ value , $ offset ] = self ::extractValue ($ remainder );
73+ $ remainder = substr ($ remainder , $ offset );
7474 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. " );
7676 }
7777
7878 return [$ value , $ this ->parseParameters ($ remainder )];
@@ -89,10 +89,10 @@ public function parseItem(Stringable|string $httpValue): array
8989 */
9090 public function parseParameters (Stringable |string $ httpValue ): array
9191 {
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. " );
9696 }
9797
9898 return $ parameters ;
@@ -170,23 +170,23 @@ public function parseInnerList(Stringable|string $httpValue): array
170170 *
171171 * @see https://tools.ietf.org/html/rfc7230#section-3.2.3
172172 */
173- private static function removeCommaSeparatedWhiteSpaces (string $ httpValue , int $ offset ): string
173+ private static function removeCommaSeparatedWhiteSpaces (string $ remainder , int $ offset ): string
174174 {
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 '' ;
178178 }
179179
180- if (1 !== preg_match (self ::REGEXP_VALID_SPACE , $ httpValue , $ found )) {
180+ if (1 !== preg_match (self ::REGEXP_VALID_SPACE , $ remainder , $ found )) {
181181 throw new SyntaxError ('The HTTP textual representation is missing an excepted comma. ' );
182182 }
183183
184- $ httpValue = substr ($ httpValue , strlen ($ found ['space ' ]));
185- if ('' === $ httpValue ) {
184+ $ remainder = substr ($ remainder , strlen ($ found ['space ' ]));
185+ if ('' === $ remainder ) {
186186 throw new SyntaxError ('The HTTP textual representation has an unexpected end of line. ' );
187187 }
188188
189- return $ httpValue ;
189+ return $ remainder ;
190190 }
191191
192192 /**
@@ -242,11 +242,11 @@ private static function extractInnerList(string $httpValue): array
242242 [$ list [], $ remainder ] = self ::extractItem ($ remainder );
243243
244244 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. " );
246246 }
247247 }
248248
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. " );
250250 }
251251
252252 /**
@@ -372,41 +372,40 @@ private static function extractDate(string $httpValue): array
372372 private static function extractString (string $ httpValue ): array
373373 {
374374 $ offset = 1 ;
375- $ originalHttpValue = $ httpValue ;
376- $ httpValue = substr ($ httpValue , $ offset );
375+ $ remainder = substr ($ httpValue , $ offset );
377376 $ output = '' ;
378377
379- while ('' !== $ httpValue ) {
380- $ char = $ httpValue [0 ];
378+ while ('' !== $ remainder ) {
379+ $ char = $ remainder [0 ];
381380 $ offset += 1 ;
382381
383382 if ('" ' === $ char ) {
384383 return [$ output , $ offset ];
385384 }
386385
387386 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. " );
389388 }
390389
391- $ httpValue = substr ($ httpValue , 1 );
390+ $ remainder = substr ($ remainder , 1 );
392391
393392 if ('\\' !== $ char ) {
394393 $ output .= $ char ;
395394 continue ;
396395 }
397396
398- $ char = $ httpValue [0 ] ?? '' ;
397+ $ char = $ remainder [0 ] ?? '' ;
399398 $ offset += 1 ;
400- $ httpValue = substr ($ httpValue , 1 );
399+ $ remainder = substr ($ remainder , 1 );
401400
402401 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. " );
404403 }
405404
406405 $ output .= $ char ;
407406 }
408407
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. " );
410409 }
411410
412411 /**
0 commit comments