Skip to content

Commit d970dc3

Browse files
committed
bugfix OrderedList::toHttpValue method
1 parent b4b7ae7 commit d970dc3

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/OrderedList.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use function array_values;
1313
use function count;
1414
use function implode;
15-
use function is_int;
1615

1716
/**
1817
* @implements IteratorAggregate<array-key, Item|InnerList>
@@ -60,15 +59,7 @@ public static function fromHttpValue(string $httpValue): self
6059

6160
public function toHttpValue(): string
6261
{
63-
$returnValue = [];
64-
foreach ($this->members as $key => $member) {
65-
$returnValue[] = match (true) {
66-
$member instanceof Item && true === $member->value() => $key.$member->parameters()->toHttpValue(),
67-
default => !is_int($key) ? $key.'='.$member->toHttpValue() : $member->toHttpValue(),
68-
};
69-
}
70-
71-
return implode(', ', $returnValue);
62+
return implode(', ', array_map(fn (InnerList|Item $member): string => $member->toHttpValue(), $this->members));
7263
}
7364

7465
public function count(): int

src/OrderedListTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,21 @@ public function it_can_be_regenerated_with_eval(): void
169169

170170
self::assertEquals($instance, $generatedInstance);
171171
}
172+
173+
/**
174+
* @test
175+
*/
176+
public function test_it_can_generate_the_same_value(): void
177+
{
178+
$res = OrderedList::fromHttpValue('token, "string", ?1; parameter, (42 42.0)');
179+
180+
$list = OrderedList::fromMembers([
181+
new Token('token'),
182+
'string',
183+
Item::from(true, ['parameter' => true]),
184+
InnerList::fromMembers([42, 42.0]),
185+
]);
186+
187+
self::assertSame($res->toHttpValue(), $list->toHttpValue());
188+
}
172189
}

0 commit comments

Comments
 (0)