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

PlayerCountryBadgeHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 14 3
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Handler\Badge;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use VideoGamesRecords\CoreBundle\Entity\Country;
7
use VideoGamesRecords\CoreBundle\Service\Ranking\Read\CountryRankingQuery;
8
9
class PlayerCountryBadgeHandler
10
{
11
    private EntityManagerInterface $em;
12
    private CountryRankingQuery $countryRankingQuery;
13
14
    public function __construct(EntityManagerInterface $em, CountryRankingQuery $countryRankingQuery)
15
    {
16
        $this->em = $em;
17
        $this->countryRankingQuery = $countryRankingQuery;
18
    }
19
20
    public function process(Country $country): void
21
    {
22
        if ($country->getBadge() === null) {
23
            return;
24
        }
25
26
        $ranking = $this->countryRankingQuery->getRanking($country->getId(), array('maxRank' => 1));
27
28
        $players = array();
29
        foreach ($ranking as $player) {
30
            $players[$player->getId()] = 0;
31
        }
32
33
        $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\PlayerBadge')->updateBadge($players, $country->getBadge());
34
    }
35
}
36