Skip to content

Commit 83eb95f

Browse files
Make nullable so we can ignore files that doesnt match our scheme
1 parent 02942fa commit 83eb95f

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/Contracts/BackupNameResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ public function generateFilename(CarbonImmutable $createdAt, string $id): string
1818
/**
1919
* Parse a filename and return the resolved data
2020
*/
21-
public function parseFilename(string $path): ResolvedBackupData;
21+
public function parseFilename(string $path): ?ResolvedBackupData;
2222
}

src/DataTransferObjects/BackupDto.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ public function getMetadata(): Metadata
3030
/**
3131
* Create a new BackupDto from a file path in the configured disk
3232
*/
33-
public static function fromFile(string $path): static
33+
public static function fromFile(string $path): ?static
3434
{
3535
$values = app(BackupNameResolver::class)->parseFilename($path);
3636

37+
if (!$values) {
38+
return null;
39+
}
40+
3741
$bytes = Storage::disk(config('backup.destination.disk'))->size($path);
3842

3943
return new static(

src/Repositories/FileBackupRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function all(): Collection
3434
{
3535
return collect($this->filesystem->allFiles($this->path))
3636
->map(BackupDto::fromFile(...))
37+
->whereInstanceOf(BackupDto::class)
3738
->sortByDesc(fn(BackupDto $backup) => $backup->created_at);
3839
}
3940

0 commit comments

Comments
 (0)