Passed
Push — develop ( 0ad6ef...06118e )
by BENARD
12:32
created

PlayerSerieBadgeHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 14 3
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\Contracts\Ranking\RankingProviderInterface;
8
use VideoGamesRecords\CoreBundle\Entity\Serie;
9
10
class PlayerSerieBadgeHandler
11
{
12
    private EntityManagerInterface $em;
13
    private RankingProviderInterface $rankingProvider; //PlayerSerieRankingQuery
14
15
    public function __construct(EntityManagerInterface $em, RankingProviderInterface $rankingProvider)
16
    {
17
        $this->em = $em;
18
        $this->rankingProvider = $rankingProvider;
19
    }
20
21
    /**
22
     * @throws ORMException
23
     */
24
    public function process(Serie $serie): void
25
    {
26
        if ($serie->getBadge() === null) {
27
            return;
28
        }
29
30
        $ranking = $this->rankingProvider->getRankingPoints($serie->getId(), array('maxRank' => 1));
31
32
        $players = array();
33
        foreach ($ranking as $playerSerie) {
34
            $players[$playerSerie->getPlayer()->getId()] = 0;
35
        }
36
37
        $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\PlayerBadge')->updateBadge($players, $serie->getBadge());
38
    }
39
}
40