Conditions | 7 |
Paths | 14 |
Total Lines | 143 |
Code Lines | 56 |
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 |
||
31 | public function handle($mixed): void |
||
32 | { |
||
33 | /** @var Player $player */ |
||
34 | $player = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Player')->find($mixed); |
||
35 | if (null === $player) { |
||
36 | return; |
||
37 | } |
||
38 | if ($player->getId() == 0) { |
||
|
|||
39 | return; |
||
40 | } |
||
41 | |||
42 | $query = $this->em->createQuery(" |
||
43 | SELECT |
||
44 | p.id, |
||
45 | SUM(g.nbChart) as nbChartMax, |
||
46 | round(AVG(pg.rankPointChart),2) as averageGameRank, |
||
47 | SUM(pg.chartRank0) as chartRank0, |
||
48 | SUM(pg.chartRank1) as chartRank1, |
||
49 | SUM(pg.chartRank2) as chartRank2, |
||
50 | SUM(pg.chartRank3) as chartRank3, |
||
51 | SUM(pg.nbChart) as nbChart, |
||
52 | SUM(pg.nbChartProven) as nbChartProven, |
||
53 | SUM(pg.pointChart) as pointChart, |
||
54 | SUM(pg.pointGame) as pointGame, |
||
55 | COUNT(DISTINCT pg.game) as nbGame |
||
56 | FROM VideoGamesRecords\CoreBundle\Entity\PlayerGame pg |
||
57 | JOIN pg.player p |
||
58 | JOIN pg.game g |
||
59 | WHERE pg.player = :player |
||
60 | AND g.boolRanking = 1 |
||
61 | GROUP BY p.id"); |
||
62 | $query->setParameter('player', $player); |
||
63 | $row = $query->getOneOrNullResult(); |
||
64 | |||
65 | $player->setNbChartMax($row['nbChartMax']); |
||
66 | $player->setAverageGameRank($row['averageGameRank']); |
||
67 | $player->setChartRank0($row['chartRank0']); |
||
68 | $player->setChartRank1($row['chartRank1']); |
||
69 | $player->setChartRank2($row['chartRank2']); |
||
70 | $player->setChartRank3($row['chartRank3']); |
||
71 | $player->setNbChart($row['nbChart']); |
||
72 | $player->setNbChartProven($row['nbChartProven']); |
||
73 | $player->setNbGame($row['nbGame']); |
||
74 | $player->setPointChart($row['pointChart']); |
||
75 | $player->setPointGame($row['pointGame']); |
||
76 | |||
77 | // 2 game Ranking |
||
78 | $data = [ |
||
79 | 'gameRank0' => 0, |
||
80 | 'gameRank1' => 0, |
||
81 | 'gameRank2' => 0, |
||
82 | 'gameRank3' => 0, |
||
83 | ]; |
||
84 | |||
85 | //----- data rank0 |
||
86 | $query = $this->em->createQuery(" |
||
87 | SELECT |
||
88 | p.id, |
||
89 | COUNT(pg.game) as nb |
||
90 | FROM VideoGamesRecords\CoreBundle\Entity\PlayerGame pg |
||
91 | JOIN pg.game g |
||
92 | JOIN pg.player p |
||
93 | WHERE pg.rankPointChart = 1 |
||
94 | AND pg.player = :player |
||
95 | AND g.nbPlayer > 1 |
||
96 | AND g.boolRanking = 1 |
||
97 | AND pg.nbEqual = 1 |
||
98 | GROUP BY p.id"); |
||
99 | |||
100 | $query->setParameter('player', $player); |
||
101 | $row = $query->getOneOrNullResult(); |
||
102 | if ($row) { |
||
103 | $data['gameRank0'] = $row['nb']; |
||
104 | } |
||
105 | //----- data rank1 to rank3 |
||
106 | $query = $this->em->createQuery(" |
||
107 | SELECT |
||
108 | p.id, |
||
109 | COUNT(pg.game) as nb |
||
110 | FROM VideoGamesRecords\CoreBundle\Entity\PlayerGame pg |
||
111 | JOIN pg.game g |
||
112 | JOIN pg.player p |
||
113 | WHERE pg.rankPointChart = :rank |
||
114 | AND pg.player = :player |
||
115 | AND g.boolRanking = 1 |
||
116 | GROUP BY p.id"); |
||
117 | |||
118 | $query->setParameter('player', $player); |
||
119 | for ($i = 1; $i <= 3; $i++) { |
||
120 | $query->setParameter('rank', $i); |
||
121 | $row = $query->getOneOrNullResult(); |
||
122 | if ($row) { |
||
123 | $data['gameRank' . $i] = $row['nb']; |
||
124 | } |
||
125 | } |
||
126 | |||
127 | $player->setGameRank0($data['gameRank0']); |
||
128 | $player->setGameRank1($data['gameRank1']); |
||
129 | $player->setGameRank2($data['gameRank2']); |
||
130 | $player->setGameRank3($data['gameRank3']); |
||
131 | |||
132 | |||
133 | // 3 Badge Ranking |
||
134 | $query = $this->em->createQuery(" |
||
135 | SELECT |
||
136 | p.id, |
||
137 | COUNT(pb.badge) as nbMasterBadge, |
||
138 | SUM(b.value) as pointBadge |
||
139 | FROM VideoGamesRecords\CoreBundle\Entity\PlayerBadge pb |
||
140 | JOIN pb.badge b |
||
141 | JOIN b.game g |
||
142 | JOIN pb.player p |
||
143 | WHERE b.type = :type |
||
144 | AND pb.player = :player |
||
145 | AND pb.ended_at IS NULL |
||
146 | AND g.boolRanking = 1 |
||
147 | GROUP BY p.id"); |
||
148 | $query->setParameter('type', 'Master'); |
||
149 | $query->setParameter('player', $player); |
||
150 | |||
151 | $row = $query->getOneOrNullResult(); |
||
152 | if ($row) { |
||
153 | $player->setNbMasterBadge($row['nbMasterBadge']); |
||
154 | $player->setPointBadge($row['pointBadge']); |
||
155 | } |
||
156 | |||
157 | // 4 nbChartWithPlatform |
||
158 | $query = $this->em->createQuery(" |
||
159 | SELECT COUNT(pc) as nb |
||
160 | FROM VideoGamesRecords\CoreBundle\Entity\PlayerChart pc |
||
161 | WHERE pc.player = :player |
||
162 | AND pc.platform IS NOT NULL"); |
||
163 | $query->setParameter('player', $player); |
||
164 | |||
165 | $nb = $query->getSingleScalarResult(); |
||
166 | $player->setNbChartWithPlatform($nb); |
||
167 | $player->getCountry()?->setBoolMaj(true); |
||
168 | |||
169 | $this->em->persist($player); |
||
170 | $this->em->flush(); |
||
171 | |||
172 | $event = new PlayerEvent($player); |
||
173 | $this->eventDispatcher->dispatch($event, VideoGamesRecordsCoreEvents::PLAYER_MAJ_COMPLETED); |
||
174 | } |
||
252 |