Skip to content

Commit c9be980

Browse files
committed
Improve Parser return type decoupling
1 parent f44228f commit c9be980

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/Dictionary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function fromPairs(iterable $pairs = []): self
6363
*/
6464
public static function fromHttpValue(string $httpValue): self
6565
{
66-
return Parser::parseDictionary($httpValue);
66+
return self::fromAssociative(Parser::parseDictionary($httpValue));
6767
}
6868

6969
public function toHttpValue(): string

src/OrderedList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static function fromMembers(iterable $members = []): self
4141
*/
4242
public static function fromHttpValue(string $httpValue): self
4343
{
44-
return Parser::parseList($httpValue);
44+
return self::fromMembers(Parser::parseList($httpValue));
4545
}
4646

4747
public function toHttpValue(): string

src/Parser.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ final class Parser
1717
* Returns an OrderedList value object from an HTTP textual representation.
1818
*
1919
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.1
20+
*
21+
* @return array<InnerList|Item|ByteSequence|Token|bool|int|float|string>
2022
*/
21-
public static function parseList(string $httpValue): OrderedList
23+
public static function parseList(string $httpValue): array
2224
{
2325
$members = [];
2426
$remainder = ltrim($httpValue, ' ');
@@ -41,15 +43,17 @@ public static function parseList(string $httpValue): OrderedList
4143
}
4244
}
4345

44-
return OrderedList::fromMembers($members);
46+
return $members;
4547
}
4648

4749
/**
4850
* Returns a Dictionary value object from an HTTP textual representation.
4951
*
5052
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.2
53+
*
54+
* @return array<string, InnerList|Item|ByteSequence|Token|bool|int|float|string>
5155
*/
52-
public static function parseDictionary(string $httpValue): Dictionary
56+
public static function parseDictionary(string $httpValue): array
5357
{
5458
$members = [];
5559
$remainder = ltrim($httpValue, ' ');
@@ -78,7 +82,7 @@ public static function parseDictionary(string $httpValue): Dictionary
7882
}
7983
}
8084

81-
return Dictionary::fromAssociative($members);
85+
return $members;
8286
}
8387

8488
/**
@@ -145,8 +149,10 @@ private static function parseBareItem(string &$httpValue): bool|float|int|string
145149
* Returns a Parameters value object from an HTTP textual representation.
146150
*
147151
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.2.3.2
152+
*
153+
* @return array<array-key, Item|Token|ByteSequence|float|int|bool|string>
148154
*/
149-
private static function parseParameters(string &$httpValue): Parameters
155+
private static function parseParameters(string &$httpValue): array
150156
{
151157
$parameters = [];
152158

@@ -162,7 +168,7 @@ private static function parseParameters(string &$httpValue): Parameters
162168
}
163169
}
164170

165-
return Parameters::fromAssociative($parameters);
171+
return $parameters;
166172
}
167173

168174
/**

0 commit comments

Comments
 (0)