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;
/**
* Provides functionality to retrieve songs in a random order
*/
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->getRandomBy(
$catalog,
$genre,
$fromYear,
$toYear
);
// @todo inefficient, but doctrine doesn't support RAND order natively
$list = iterator_to_array($list);
shuffle($list);
return array_slice($list, 0, $limit);