Skip to content

Commit e72787d

Browse files
committed
Move and rename method
1 parent 8747a5f commit e72787d

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/Support/LazyBodyPartStream.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,6 @@ public function __construct(
2727
protected BodyStructurePart $part,
2828
) {}
2929

30-
/**
31-
* Fetch the content from the server if not already cached.
32-
*/
33-
protected function fetchContent(): string
34-
{
35-
if ($this->content === null) {
36-
$this->content = BodyPartDecoder::binary(
37-
$this->part,
38-
$this->message->bodyPart($this->part->partNumber())
39-
) ?? '';
40-
}
41-
42-
return $this->content;
43-
}
44-
4530
/**
4631
* {@inheritDoc}
4732
*/
@@ -74,7 +59,7 @@ public function detach()
7459
*/
7560
public function getSize(): ?int
7661
{
77-
return strlen($this->fetchContent());
62+
return strlen($this->getOrFetchContent());
7863
}
7964

8065
/**
@@ -90,7 +75,7 @@ public function tell(): int
9075
*/
9176
public function eof(): bool
9277
{
93-
return $this->position >= strlen($this->fetchContent());
78+
return $this->position >= strlen($this->getOrFetchContent());
9479
}
9580

9681
/**
@@ -106,7 +91,7 @@ public function isSeekable(): bool
10691
*/
10792
public function seek(int $offset, int $whence = SEEK_SET): void
10893
{
109-
$content = $this->fetchContent();
94+
$content = $this->getOrFetchContent();
11095
$size = strlen($content);
11196

11297
$this->position = match ($whence) {
@@ -150,7 +135,7 @@ public function isReadable(): bool
150135
*/
151136
public function read(int $length): string
152137
{
153-
$content = $this->fetchContent();
138+
$content = $this->getOrFetchContent();
154139

155140
$result = substr($content, $this->position, $length);
156141

@@ -164,7 +149,7 @@ public function read(int $length): string
164149
*/
165150
public function getContents(): string
166151
{
167-
$content = $this->fetchContent();
152+
$content = $this->getOrFetchContent();
168153

169154
$result = substr($content, $this->position);
170155

@@ -176,7 +161,7 @@ public function getContents(): string
176161
/**
177162
* {@inheritDoc}
178163
*/
179-
public function getMetadata(?string $key = null): mixed
164+
public function getMetadata(?string $key = null): ?array
180165
{
181166
return $key === null ? [] : null;
182167
}
@@ -188,4 +173,19 @@ public function write(string $string): int
188173
{
189174
throw new RuntimeException('Stream is not writable');
190175
}
176+
177+
/**
178+
* Fetch the content from the server if not already cached.
179+
*/
180+
protected function getOrFetchContent(): string
181+
{
182+
if ($this->content === null) {
183+
$this->content = BodyPartDecoder::binary(
184+
$this->part,
185+
$this->message->bodyPart($this->part->partNumber())
186+
) ?? '';
187+
}
188+
189+
return $this->content;
190+
}
191191
}

0 commit comments

Comments
 (0)