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

RandomSongsRetriever::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 0
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 1
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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