PlayerMasterBadgeHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 10
c 0
b 0
f 0
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 10 2
A __construct() 0 7 1
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