Conditions | 4 |
Paths | 5 |
Total Lines | 69 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
16 | public function handle($mixed): void |
||
17 | { |
||
18 | $serie = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Serie')->find($mixed); |
||
19 | if (null === $serie) { |
||
20 | return; |
||
21 | } |
||
22 | |||
23 | // Delete old data |
||
24 | $query = $this->em->createQuery('DELETE VideoGamesRecords\CoreBundle\Entity\PlayerSerie us WHERE us.serie = :serie'); |
||
25 | $query->setParameter('serie', $serie); |
||
26 | $query->execute(); |
||
27 | |||
28 | // Select data |
||
29 | $query = $this->em->createQuery(" |
||
30 | SELECT |
||
31 | p.id as idPlayer, |
||
32 | '' as rankPointChart, |
||
33 | '' as rankMedal, |
||
34 | SUM(pg.chartRank0) as chartRank0, |
||
35 | SUM(pg.chartRank1) as chartRank1, |
||
36 | SUM(pg.chartRank2) as chartRank2, |
||
37 | SUM(pg.chartRank3) as chartRank3, |
||
38 | SUM(pg.chartRank4) as chartRank4, |
||
39 | SUM(pg.chartRank5) as chartRank5, |
||
40 | SUM(pg.pointGame) as pointGame, |
||
41 | SUM(pg.pointChart) as pointChart, |
||
42 | SUM(pg.pointChartWithoutDlc) as pointChartWithoutDlc, |
||
43 | SUM(pg.nbChart) as nbChart, |
||
44 | SUM(pg.nbChartWithoutDlc) as nbChartWithoutDlc, |
||
45 | SUM(pg.nbChartProven) as nbChartProven, |
||
46 | SUM(pg.nbChartProvenWithoutDlc) as nbChartProvenWithoutDlc, |
||
47 | COUNT(DISTINCT pg.game) as nbGame |
||
48 | FROM VideoGamesRecords\CoreBundle\Entity\PlayerGame pg |
||
49 | JOIN pg.game g |
||
50 | JOIN pg.player p |
||
51 | WHERE g.serie = :serie |
||
52 | GROUP BY p.id |
||
53 | ORDER BY pointChart DESC"); |
||
54 | |||
55 | $query->setParameter('serie', $serie); |
||
56 | $result = $query->getResult(); |
||
57 | |||
58 | $list = []; |
||
59 | foreach ($result as $row) { |
||
60 | $list[] = $row; |
||
61 | } |
||
62 | |||
63 | $list = Ranking::addRank($list, 'rankPointChart', ['pointChart']); |
||
64 | $list = Ranking::order($list, ['chartRank0' => SORT_DESC, 'chartRank1' => SORT_DESC, 'chartRank2' => SORT_DESC, 'chartRank3' => SORT_DESC]); |
||
65 | $list = Ranking::addRank($list, 'rankMedal', ['chartRank0', 'chartRank1', 'chartRank2', 'chartRank3', 'chartRank4', 'chartRank5']); |
||
66 | |||
67 | $normalizer = new ObjectNormalizer(); |
||
68 | $serializer = new Serializer([$normalizer]); |
||
69 | |||
70 | |||
71 | foreach ($list as $row) { |
||
72 | $playerSerie = $serializer->denormalize( |
||
73 | $row, |
||
74 | 'VideoGamesRecords\CoreBundle\Entity\PlayerSerie' |
||
75 | ); |
||
76 | $playerSerie->setPlayer($this->em->getReference('VideoGamesRecords\CoreBundle\Entity\Player', $row['idPlayer'])); |
||
77 | $playerSerie->setSerie($serie); |
||
78 | |||
79 | $this->em->persist($playerSerie); |
||
80 | $this->em->flush(); |
||
81 | } |
||
82 | |||
83 | $event = new SerieEvent($serie); |
||
84 | $this->eventDispatcher->dispatch($event, VideoGamesRecordsCoreEvents::PLAYER_SERIE_MAJ_COMPLETED); |
||
85 | } |
||
87 |