Skip to content

Commit

Permalink
Remove unnecessary extra type check for Iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
gapple committed Jan 6, 2024
1 parent 2beaae7 commit 76779d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public static function serializeItem($value, ?object $parameters = null): string
public static function serializeList(iterable $value): string
{
if ($value instanceof \Traversable) {
if ($value instanceof \IteratorAggregate) {
$value = $value->getIterator();
}
// @todo Checking for Traversable is not required for PHP ^8.2.0.
$value = iterator_to_array($value);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/SerializeListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,19 @@ public function testIterable(): void
$serialized
);
}

public function testArray(): void
{
$list = [
new Item('test'),
new Item(42),
];

$serialized = Serializer::serializeList($list);

$this->assertEquals(
'"test", 42',
$serialized
);
}
}

0 comments on commit 76779d7

Please sign in to comment.