Passed
Push — main ( 1d1c5b...83bc52 )
by Daniel
04:23
created

CoverArtDataProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 31
ccs 9
cts 9
cp 1
rs 10
wmc 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Component\SubSonic;
6
7
use Usox\HyperSonic\FeatureSet\V1161\Contract\GetCoverArtDataProviderInterface;
8
use Uxmp\Core\Component\Art\ArtContentRetrieverInterface;
9
use Uxmp\Core\Component\Art\Exception\ArtContentException;
10
use Uxmp\Core\Orm\Model\ArtistInterface;
11
use Uxmp\Core\Orm\Repository\ArtistRepositoryInterface;
12
13
/**
14
 * Retrieves the cover art for items which support art
15
 */
16
final class CoverArtDataProvider implements GetCoverArtDataProviderInterface
17
{
18 2
    public function __construct(
19
        private readonly ArtistRepositoryInterface $artistRepository,
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 19 at column 25
Loading history...
20
        private readonly ArtContentRetrieverInterface $artContentRetriever,
21
    ) {
22
    }
23
24
    /**
25
     * @return array{
26
     *  contentType: string,
27
     *  art: string
28
     * }
29
     */
30 2
    public function getArt(string $coverArtId): array
31
    {
32
        // @todo Currently artists only; Merge with Api\Art\ArtApplication
33 2
        $str = explode('-', $coverArtId);
34
35
        /** @var ArtistInterface $artist */
36 2
        $artist = $this->artistRepository->find((int) $str[1]);
37
38
        try {
39 2
            $artContent = $this->artContentRetriever->retrieve($artist);
40 1
        } catch (ArtContentException) {
41 1
            $artContent = [];
42
        }
43
44
        return [
45 2
            'art' => $artContent['content'] ?? '',
46 2
            'contentType' => $artContent['mimeType'] ?? '',
47
        ];
48
    }
49
}
50