for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Uxmp\Core\Component\Song;
use Uxmp\Core\Orm\Model\CatalogInterface;
use Uxmp\Core\Orm\Model\GenreInterface;
use Uxmp\Core\Orm\Model\SongInterface;
use Uxmp\Core\Orm\Repository\SongRepositoryInterface;
final class RandomSongsRetriever implements RandomSongsRetrieverInterface
{
public function __construct(
private readonly SongRepositoryInterface $songRepository,
) {
}
/**
* @return array<SongInterface>
*/
public function retrieve(
int $limit,
?CatalogInterface $catalog = null,
?GenreInterface $genre = null,
?int $fromYear = null,
?int $toYear = null,
): array {
$list = $this->songRepository->findAll();
// @todo inefficient, but doctrine doesn't support RAND order natively
shuffle($list);
return array_slice($list, 0, $limit);