Skip to content

Commit e93e2ee

Browse files
committed
refactor: returns null for non-type getters
1 parent c19aa8d commit e93e2ee

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/Files/DTO/File.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,12 @@ public function getFileType(): FileTypeEnum
158158
*
159159
* @since n.e.x.t
160160
*
161-
* @return string The URL.
162-
* @throws \RuntimeException If the file is not remote.
161+
* @return string|null The URL, or null if not a remote file.
163162
*/
164-
public function getUrl(): string
163+
public function getUrl(): ?string
165164
{
166165
if (!$this->fileType->isRemote()) {
167-
throw new \RuntimeException('Cannot get URL for non-remote file.');
166+
return null;
168167
}
169168

170169
return $this->data;
@@ -175,30 +174,28 @@ public function getUrl(): string
175174
*
176175
* @since n.e.x.t
177176
*
178-
* @return string The plain base64-encoded data (without data URI prefix).
179-
* @throws \RuntimeException If the file is not inline.
177+
* @return string|null The plain base64-encoded data (without data URI prefix), or null if not an inline file.
180178
*/
181-
public function getBase64Data(): string
179+
public function getBase64Data(): ?string
182180
{
183181
if (!$this->fileType->isInline()) {
184-
throw new \RuntimeException('Cannot get base64 data for non-inline file.');
182+
return null;
185183
}
186184

187185
return $this->data;
188186
}
189187

190188
/**
191-
* Gets the data as a data URL for inline files.
189+
* Gets the data as a data URI for inline files.
192190
*
193191
* @since n.e.x.t
194192
*
195-
* @return string The data URL in format: data:[mimeType];base64,[data].
196-
* @throws \RuntimeException If the file is not inline.
193+
* @return string|null The data URI in format: data:[mimeType];base64,[data], or null if not an inline file.
197194
*/
198-
public function getDataUrl(): string
195+
public function getDataUri(): ?string
199196
{
200197
if (!$this->fileType->isInline()) {
201-
throw new \RuntimeException('Cannot get data URL for non-inline file.');
198+
return null;
202199
}
203200

204201
return sprintf('data:%s;base64,%s', $this->getMimeType(), $this->data);

0 commit comments

Comments
 (0)