Skip to content

Commit 1c0051a

Browse files
fix(Storage): add null check for $stream->getMetadata (#9071)
1 parent 63b8cfb commit 1c0051a

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

Storage/src/ReadStream.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ public function getSize(): ?int
6060
*/
6161
private function getSizeFromMetadata(): int
6262
{
63-
foreach ($this->stream->getMetadata('wrapper_data') as $value) {
63+
$metadata = $this->stream->getMetadata('wrapper_data');
64+
65+
if (is_null($metadata)) {
66+
return 0;
67+
}
68+
69+
foreach ($metadata as $value) {
6470
if (substr($value, 0, 15) == 'Content-Length:') {
6571
return (int) substr($value, 16);
6672
}

Storage/tests/Unit/ReadStreamTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,15 @@ public function testNoContentLengthHeader()
7373

7474
$this->assertEquals(0, $stream->getSize());
7575
}
76+
77+
public function testReturnsZeroWhenGetSizeIsZeroAndWrapperDataIsNull()
78+
{
79+
$httpStream = $this->prophesize(StreamInterface::class);
80+
$httpStream->getSize()->willReturn(null);
81+
$httpStream->getMetadata('wrapper_data')->willReturn(null);
82+
83+
$stream = new ReadStream($httpStream->reveal());
84+
85+
$this->assertEquals(0, $stream->getSize());
86+
}
7687
}

0 commit comments

Comments
 (0)