Skip to content

Commit b7b7b63

Browse files
committed
refactor: splits up data and url parameters
1 parent e93e2ee commit b7b7b63

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
@@ -29,9 +29,14 @@ class File implements WithJsonSchemaInterface
2929
private FileTypeEnum $fileType;
3030

3131
/**
32-
* @var string The file data (URL for remote, base64 for inline).
32+
* @var string|null The URL for remote files.
3333
*/
34-
private string $data;
34+
private ?string $url = null;
35+
36+
/**
37+
* @var string|null The base64 data for inline files.
38+
*/
39+
private ?string $data = null;
3540

3641
/**
3742
* Constructor.
@@ -62,7 +67,7 @@ private function detectAndProcessFile(string $file, ?string $providedMimeType):
6267
// Check if it's a URL
6368
if ($this->isUrl($file)) {
6469
$this->fileType = FileTypeEnum::remote();
65-
$this->data = $file;
70+
$this->url = $file;
6671
$this->mimeType = $this->determineMimeType($providedMimeType, null, $file);
6772
return;
6873
}
@@ -162,11 +167,7 @@ public function getFileType(): FileTypeEnum
162167
*/
163168
public function getUrl(): ?string
164169
{
165-
if (!$this->fileType->isRemote()) {
166-
return null;
167-
}
168-
169-
return $this->data;
170+
return $this->url;
170171
}
171172

172173
/**
@@ -178,10 +179,6 @@ public function getUrl(): ?string
178179
*/
179180
public function getBase64Data(): ?string
180181
{
181-
if (!$this->fileType->isInline()) {
182-
return null;
183-
}
184-
185182
return $this->data;
186183
}
187184

@@ -194,7 +191,7 @@ public function getBase64Data(): ?string
194191
*/
195192
public function getDataUri(): ?string
196193
{
197-
if (!$this->fileType->isInline()) {
194+
if ($this->data === null) {
198195
return null;
199196
}
200197

0 commit comments

Comments
 (0)