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

ArtistListDataProvider::getArtists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Component\SubSonic;
6
7
use DateTimeInterface;
8
use Generator;
9
use Usox\HyperSonic\FeatureSet\V1161\Contract\ArtistListDataProviderInterface;
10
use Uxmp\Core\Orm\Repository\ArtistRepositoryInterface;
11
12
/**
13
 * Provides the complete list of available artists
14
 */
15
final class ArtistListDataProvider implements ArtistListDataProviderInterface
16
{
17
    public function __construct(
18
        private ArtistRepositoryInterface $artistRepository
19
    ) {
20
    }
21
22
    /**
23
     * @return array<string>
24
     *
25
     * @todo implement stripping of articles (like 'the, el, los, ...')
26
     */
27
    public function getIgnoredArticles(): array
28
    {
29
        return [];
30
    }
31
32
    /**
33
     * @return Generator<array{
34
     *  id: string,
35
     *  name: string,
36
     *  coverArtId: string,
37
     *  artistImageUrl: string,
38
     *  albumCount: int,
39
     *  starred: null|DateTimeInterface
40
     * }>
41
     */
42
    public function getArtists(
43
        ?string $musicFolderId
44
    ): Generator {
45
        foreach ($this->artistRepository->findBy([], ['title' => 'ASC']) as $artist) {
46
            $artistId = $artist->getId();
47
48
            yield [
49
                'id' => (string) $artistId,
50
                'name' => (string) $artist->getTitle(),
51
                'artistImageUrl' => '',
52
                'coverArtId' => 'artist-'.$artistId,
53
                'albumCount' => $artist->getAlbumCount(),
54
                'starred' => null,
55
            ];
56
        }
57
    }
58
}
59