Passed
Push — main ( 464f55...4d72a0 )
by Daniel
14:54 queued 11:08
created

RandomSongsRetriever   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 4
c 1
b 0
f 1
dl 0
loc 22
ccs 0
cts 6
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A retrieve() 0 12 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Component\Song;
6
7
use Uxmp\Core\Orm\Model\CatalogInterface;
8
use Uxmp\Core\Orm\Model\GenreInterface;
9
use Uxmp\Core\Orm\Model\SongInterface;
10
use Uxmp\Core\Orm\Repository\SongRepositoryInterface;
11
12
final class RandomSongsRetriever implements RandomSongsRetrieverInterface
13
{
14
    public function __construct(
15
        private readonly SongRepositoryInterface $songRepository,
16
    ) {
17
    }
18
19
    /**
20
     * @return array<SongInterface>
21
     */
22
    public function retrieve(
23
        int $limit,
24
        ?CatalogInterface $catalog = null,
25
        ?GenreInterface $genre = null,
26
        ?int $fromYear = null,
27
        ?int $toYear = null,
28
    ): array {
29
        $list = $this->songRepository->findAll();
30
        // @todo inefficient, but doctrine doesn't support RAND order natively
31
        shuffle($list);
32
33
        return array_slice($list, 0, $limit);
34
    }
35
}
36