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

PlayerCountryBadgeHandler::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
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