for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace VideoGamesRecords\CoreBundle\Handler\Badge;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Exception\ORMException;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use VideoGamesRecords\CoreBundle\Contracts\Ranking\RankingProviderInterface;
use VideoGamesRecords\CoreBundle\Entity\Game;
use VideoGamesRecords\CoreBundle\Ranking\Provider\Player\PlayerGameRankingProvider;
class PlayerMasterBadgeHandler
{
private EntityManagerInterface $em;
private RankingProviderInterface $rankingProvider;
public function __construct(
EntityManagerInterface $em,
#[Autowire(service: PlayerGameRankingProvider::class)]
RankingProviderInterface $rankingProvider
) {
$this->em = $em;
$this->rankingProvider = $rankingProvider;
}
/**
* @throws ORMException
*/
public function process(Game $game): void
//----- get ranking with maxRank = 1
$ranking = $this->rankingProvider->getRankingPoints($game->getId(), ['maxRank' => 1]);
$players = array();
foreach ($ranking as $playerGame) {
$players[$playerGame->getPlayer()->getId()] = 0;
$this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\PlayerBadge')->updateBadge($players, $game->getBadge());