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