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

ArtistListDataProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 40
ccs 10
cts 10
cp 1
rs 10
wmc 4
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
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 18 at column 25
Loading history...
19
    ) {
20
    }
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
            yield [
49 1
                'id' => (string) $artistId,
50 1
                'name' => (string) $artist->getTitle(),
51
                'artistImageUrl' => '',
52 1
                'coverArtId' => 'artist-'.$artistId,
53 1
                'albumCount' => $artist->getAlbumCount(),
54
                'starred' => null,
55
            ];
56
        }
57
    }
58
}
59