| Total Complexity | 4 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | final readonly class ArtistDataProvider implements ArtistDataProviderInterface |
||
|
|
|||
| 15 | { |
||
| 16 | 2 | public function __construct( |
|
| 17 | private ArtistRepositoryInterface $artistRepository |
||
| 18 | ) { |
||
| 19 | 2 | } |
|
| 20 | |||
| 21 | /** |
||
| 22 | * @return null|array{ |
||
| 23 | * id: int|string, |
||
| 24 | * name: string, |
||
| 25 | * coverArtId: string, |
||
| 26 | * albumCount: int, |
||
| 27 | * artistImageUrl: string, |
||
| 28 | * albums: array<array{ |
||
| 29 | * id: int|string, |
||
| 30 | * name: string, |
||
| 31 | * coverArtId: string, |
||
| 32 | * songCount: int, |
||
| 33 | * createDate: DateTimeInterface|null, |
||
| 34 | * duration: int, |
||
| 35 | * artistName: string, |
||
| 36 | * artistId: int|string, |
||
| 37 | * year?: string, |
||
| 38 | * genre?: string, |
||
| 39 | * playCount?: int |
||
| 40 | * }> |
||
| 41 | * } |
||
| 42 | */ |
||
| 43 | 2 | public function getArtist( |
|
| 44 | string $artistId |
||
| 45 | ): ?array { |
||
| 46 | 2 | $artist = $this->artistRepository->find((int) $artistId); |
|
| 47 | |||
| 48 | 2 | if ($artist === null) { |
|
| 49 | 1 | return null; |
|
| 50 | } |
||
| 51 | |||
| 52 | 1 | $albums = []; |
|
| 53 | 1 | $artistName = (string) $artist->getTitle(); |
|
| 54 | |||
| 55 | 1 | foreach ($artist->getAlbums() as $album) { |
|
| 56 | 1 | $albumId = $album->getId(); |
|
| 57 | |||
| 58 | 1 | $albums[] = [ |
|
| 59 | 1 | 'id' => $albumId, |
|
| 60 | 1 | 'name' => (string) $album->getTitle(), |
|
| 61 | 1 | 'coverArtId' => 'album-'.$albumId, |
|
| 62 | 1 | 'songCount' => $album->getSongCount(), |
|
| 63 | 1 | 'createDate' => null, // @todo implement, |
|
| 64 | 1 | 'duration' => $album->getLength(), |
|
| 65 | 1 | 'artistName' => $artistName, |
|
| 66 | 1 | 'artistId' => $artistId, |
|
| 67 | 1 | ]; |
|
| 68 | } |
||
| 69 | |||
| 70 | 1 | return [ |
|
| 71 | 1 | 'id' => $artistId, |
|
| 72 | 1 | 'name' => $artistName, |
|
| 73 | 1 | 'coverArtId' => 'artist-'.$artistId, |
|
| 74 | 1 | 'artistImageUrl' => '', |
|
| 75 | 1 | 'albumCount' => $artist->getAlbumCount(), |
|
| 76 | 1 | 'albums' => $albums, |
|
| 77 | 1 | ]; |
|
| 80 |