Skip to content

Commit

Permalink
Handle null value and non existant value
Browse files Browse the repository at this point in the history
In our project i have handled saving the data to a storage driver myself (added it well before it was included in the current package). 

When adding a test for this functionality in my project the latest version of the code throws an error about attempting to get a value from a null. 

I've seen you check for the values presence in other methods in this class, so i added it here too.
  • Loading branch information
bretto36 authored and jdavidbakr committed Aug 6, 2023
1 parent e3a412a commit 61c4387
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Concerns/IsSentEmailModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ public function getContentAttribute(): ?string
if ($content = $this->attributes['content']) {
return $content;
}
if ($contentFilePath = $this->meta->get('content_file_path')) {
try {
return Storage::disk(config('mail-tracker.tracker-filesystem'))->get($contentFilePath);
} catch (FileNotFoundException $e) {
return null;
if ($this->meta?->has('content_file_path')) {
if ($contentFilePath = $this->meta->get('content_file_path')) {
try {
return Storage::disk(config('mail-tracker.tracker-filesystem'))->get($contentFilePath);
} catch (FileNotFoundException $e) {
return null;
}
}
}
return null;
Expand Down Expand Up @@ -191,4 +193,4 @@ public function fillContent(string $originalHtml, string $hash)

$this->content = $databaseContent;
}
}
}

0 comments on commit 61c4387

Please sign in to comment.