for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Uxmp\Core\Component\Album;
use Uxmp\Core\Component\Artist\ArtistCoverUpdaterInterface;
use Uxmp\Core\Component\Config\ConfigProviderInterface;
use Uxmp\Core\Component\Tag\Container\AudioFileInterface;
use Uxmp\Core\Orm\Model\AlbumInterface;
final class AlbumCoverUpdater implements AlbumCoverUpdaterInterface
{
public function __construct(
private readonly ConfigProviderInterface $config,
private readonly ArtistCoverUpdaterInterface $artistCoverUpdater
) {
}
public function update(
AlbumInterface $album,
AudioFileInterface $audioFile,
): void {
$image = $audioFile->getAlbumCover();
if ($image !== null) {
$extension = match ($image['image_mime']) {
'image/jpeg' => 'jpg',
'image/png' => 'png',
'image/gif' => 'gif',
default => null,
};
if ($extension === null) {
return;
$destination = sprintf(
'%s/img/album',
$this->config->getAssetPath()
);
$filename = sprintf(
'%s/%s.%s',
$destination,
$album->getMbid(),
$extension
if (!file_exists($filename)) {
file_put_contents($filename, $image['data']);
$this->artistCoverUpdater->update($album->getArtist());