Passed
Push — develop ( e920eb...9cd2fd )
by BENARD
05:00
created

PlayerCountryRankingHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 2
A getCountryRepository() 0 3 1
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Ranking\Command\Player;
4
5
use Doctrine\ORM\EntityRepository;
6
use VideoGamesRecords\CoreBundle\Event\CountryEvent;
7
use VideoGamesRecords\CoreBundle\Handler\Ranking\AbstractRankingHandler;
8
use VideoGamesRecords\CoreBundle\Tools\Ranking;
9
use VideoGamesRecords\CoreBundle\VideoGamesRecordsCoreEvents;
10
11
class PlayerCountryRankingHandler extends AbstractRankingHandler
12
{
13
    /*public function majAll()
14
    {
15
        $countries = $this->getCountryRepository()->findBy(['boolMaj' => true]);
16
        foreach ($countries as $country) {
17
            $this->handle($country->getId());
18
            $country->setBoolMaj(false);
19
        }
20
        $this->em->flush();
21
    }*/
22
23
    public function handle($mixed): void
24
    {
25
        $country = $this->getCountryRepository()->find($mixed);
26
        if (null === $country) {
27
            return;
28
        }
29
30
        $players = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Player')
31
            ->findBy(array('country' => $country), array('rankPointChart' => 'ASC'));
32
        Ranking::addObjectRank($players, 'rankCountry', array('rankPointChart'));
33
        $this->em->flush();
34
35
        $event = new CountryEvent($country);
36
        $this->eventDispatcher->dispatch($event, VideoGamesRecordsCoreEvents::COUNTRY_MAJ_COMPLETED);
37
    }
38
39
    private function getCountryRepository(): EntityRepository
40
    {
41
        return $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Country');
42
    }
43
}
44