Test Setup Failed
Push — main ( 7bb2c5...c5b0e8 )
by Daniel
03:55
created

CoverArtDataProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getArt() 0 17 2
A __construct() 0 4 1
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
    public function __construct(
19
        private ArtistRepositoryInterface $artistRepository,
20
        private ArtContentRetrieverInterface $artContentRetriever,
21
    ) {
22
    }
23
24
    /**
25
     * @return array{
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{ at position 2 could not be parsed: the token is null at position 2.
Loading history...
26
     *  contentType: string,
27
     *  art: string
28
     * }
29
     */
30
    public function getArt(string $coverArtId): array
31
    {
32
        // @todo Currently artists only; Merge with Api\Art\ArtApplication
33
        $str = explode('-', $coverArtId);
34
35
        /** @var ArtistInterface $artist */
36
        $artist = $this->artistRepository->find((int) $str[1]);
37
38
        try {
39
            $artContent = $this->artContentRetriever->retrieve($artist);
40
        } catch (ArtContentException) {
41
            $artContent = [];
42
        }
43
44
        return [
45
            'art' => $artContent['content'] ?? '',
46
            'contentType' => $artContent['mimeType'] ?? '',
47
        ];
48
    }
49
}
50