Skip to content

Commit d77fe86

Browse files
committed
Parser should return array and not Container Value Objects
1 parent 4876d0f commit d77fe86

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/InnerList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static function filterMember(Item|ByteSequence|Token|bool|int|float|stri
6565

6666
public static function fromHttpValue(string $httpValue): self
6767
{
68-
return Parser::parseInnerList($httpValue);
68+
return InnerList::fromList(...Parser::parseInnerList($httpValue));
6969
}
7070

7171
public function toHttpValue(): string

src/Parser.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,13 @@ public static function parseDictionary(string $httpValue): array
9999
* Returns a InnerList value object from an HTTP textual representation.
100100
*
101101
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.1.2
102+
*
103+
* @return array{
104+
* 0:array<Item|ByteSequence|Token|bool|int|float|string>,
105+
* 1:array<string,Item|ByteSequence|Token|bool|int|float|string>
106+
* }
102107
*/
103-
public static function parseInnerList(string $httpValue): InnerList
108+
public static function parseInnerList(string $httpValue): array
104109
{
105110
if ('(' !== $httpValue[0]) {
106111
throw new SyntaxError("The HTTP textual representation `$httpValue` for a inner list is missing a parenthesis.");
@@ -125,7 +130,9 @@ public static function parseInnerList(string $httpValue): InnerList
125130
private static function parseItemOrInnerList(string $httpValue): array
126131
{
127132
if ('(' === $httpValue[0]) {
128-
return self::parseInnerListValue($httpValue);
133+
[$innerList, $offset] = self::parseInnerListValue($httpValue);
134+
135+
return [InnerList::fromList($innerList[0], $innerList[1]), $offset];
129136
}
130137

131138
[$value, $offset] = self::parseBareItem($httpValue);
@@ -142,7 +149,10 @@ private static function parseItemOrInnerList(string $httpValue): array
142149
*
143150
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.1.2
144151
*
145-
* @return array{0:InnerList, 1:int}
152+
* @return array{0:array{
153+
* 0:array<Item|ByteSequence|Token|bool|int|float|string>,
154+
* 1:array<string,Item|ByteSequence|Token|bool|int|float|string>
155+
* }, 1:int}
146156
*/
147157
private static function parseInnerListValue(string $httpValue): array
148158
{
@@ -156,7 +166,7 @@ private static function parseInnerListValue(string $httpValue): array
156166
[$parameters, $offset] = self::parseParameters($remainder);
157167
$remainder = substr($remainder, $offset);
158168

159-
return [InnerList::fromList($members, $parameters), strlen($httpValue) - strlen($remainder)];
169+
return [[$members, $parameters], strlen($httpValue) - strlen($remainder)];
160170
}
161171

162172
[$value, $offset] = self::parseBareItem($remainder);

0 commit comments

Comments
 (0)