count() === 1) { return $this->getLocalPath($songs->first()); } return (new SongZipArchive()) ->addSongs($songs) ->finish() ->getPath(); } public function getLocalPath(Song $song): ?string { if (!$song->storage->supported()) { return null; } if ($song->storage === SongStorageType::LOCAL) { return File::exists($song->path) ? $song->path : null; } switch ($song->storage) { case SongStorageType::DROPBOX: /** @var CloudStorage $cloudStorage */ $cloudStorage = app(DropboxStorage::class); break; case SongStorageType::S3: case SongStorageType::S3_LAMBDA: /** @var CloudStorage $cloudStorage */ $cloudStorage = app(S3CompatibleStorage::class); break; default: return null; } return $cloudStorage->copyToLocal($song); } }