Passed
Push — main ( e933de...5ef56a )
by Daniel
03:35
created

ArtistListDataProvider::getArtists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 13
ccs 10
cts 10
cp 1
rs 9.9666
cc 2
nc 2
nop 1
crap 2
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 2
    public function __construct(
18
        private readonly ArtistRepositoryInterface $artistRepository
19
    ) {
20 2
    }
21
22
    /**
23
     * @return array<string>
24
     *
25
     * @todo implement stripping of articles (like 'the, el, los, ...')
26
     */
27 1
    public function getIgnoredArticles(): array
28
    {
29 1
        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 1
    public function getArtists(
43
        ?string $musicFolderId
44
    ): Generator {
45 1
        foreach ($this->artistRepository->findBy([], ['title' => 'ASC']) as $artist) {
46 1
            $artistId = $artist->getId();
47
48 1
            yield [
49 1
                'id' => (string) $artistId,
50 1
                'name' => (string) $artist->getTitle(),
51 1
                'artistImageUrl' => '',
52 1
                'coverArtId' => 'artist-'.$artistId,
53 1
                'albumCount' => $artist->getAlbumCount(),
54 1
                'starred' => null,
55 1
            ];
56
        }
57
    }
58
}
59