Passed
Push — develop ( 90be87...f1c6f2 )
by BENARD
04:34
created

PlayerMasterBadgeHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 10 2
A __construct() 0 4 1
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Handler\Badge;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\Exception\ORMException;
7
use VideoGamesRecords\CoreBundle\Entity\Game;
8
use VideoGamesRecords\CoreBundle\Service\Ranking\Read\PlayerGameRankingQuery;
9
10
class PlayerMasterBadgeHandler
11
{
12
    private EntityManagerInterface $em;
13
    private PlayerGameRankingQuery $playerGameRankingQuery;
14
15
    public function __construct(EntityManagerInterface $em, PlayerGameRankingQuery $playerGameRankingQuery)
16
    {
17
        $this->em = $em;
18
        $this->playerGameRankingQuery = $playerGameRankingQuery;
19
    }
20
21
    /**
22
     * @throws ORMException
23
     */
24
    public function process(Game $game): void
25
    {
26
        //----- get ranking with maxRank = 1
27
        $ranking = $this->playerGameRankingQuery->getRankingPoints($game->getId(), ['maxRank' => 1]);
28
        $players = array();
29
        foreach ($ranking as $playerGame) {
30
            $players[$playerGame->getPlayer()->getId()] = 0;
31
        }
32
33
        $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\PlayerBadge')->updateBadge($players, $game->getBadge());
0 ignored issues
show
Bug introduced by
It seems like $game->getBadge() can also be of type null; however, parameter $badge of VideoGamesRecords\CoreBu...pository::updateBadge() does only seem to accept VideoGamesRecords\CoreBundle\Entity\Badge, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\PlayerBadge')->updateBadge($players, /** @scrutinizer ignore-type */ $game->getBadge());
Loading history...
34
    }
35
}
36