PlayerMasterBadgeHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Handler\Badge;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\ORM\Exception\ORMException;
9
use Symfony\Component\DependencyInjection\Attribute\Autowire;
10
use VideoGamesRecords\CoreBundle\Contracts\Ranking\RankingProviderInterface;
11
use VideoGamesRecords\CoreBundle\Entity\Game;
12
use VideoGamesRecords\CoreBundle\Ranking\Provider\Player\PlayerGameRankingProvider;
13
14
class PlayerMasterBadgeHandler
15
{
16
    private EntityManagerInterface $em;
17
    private RankingProviderInterface $rankingProvider;
18
19
    public function __construct(
20
        EntityManagerInterface $em,
21
        #[Autowire(service: PlayerGameRankingProvider::class)]
22
        RankingProviderInterface $rankingProvider
23
    ) {
24
        $this->em = $em;
25
        $this->rankingProvider = $rankingProvider;
26
    }
27
28
    /**
29
     * @throws ORMException
30
     */
31
    public function process(Game $game): void
32
    {
33
        //----- get ranking with maxRank = 1
34
        $ranking = $this->rankingProvider->getRankingPoints($game->getId(), ['maxRank' => 1]);
35
        $players = array();
36
        foreach ($ranking as $playerGame) {
37
            $players[$playerGame->getPlayer()->getId()] = 0;
38
        }
39
40
        $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\PlayerBadge')->updateBadge($players, $game->getBadge());
41
    }
42
}
43