Conditions | 7 |
Paths | 25 |
Total Lines | 120 |
Code Lines | 48 |
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 Team $team */ |
||
34 | $team = $this->em->getRepository('VideoGamesRecords\CoreBundle\Entity\Team')->find($mixed); |
||
35 | if (null === $team) { |
||
36 | return; |
||
37 | } |
||
38 | |||
39 | $query = $this->em->createQuery(" |
||
40 | SELECT |
||
41 | t.id, |
||
42 | round(AVG(tg.rankPointChart),2) as averageGameRank, |
||
43 | SUM(tg.chartRank0) as chartRank0, |
||
44 | SUM(tg.chartRank1) as chartRank1, |
||
45 | SUM(tg.chartRank2) as chartRank2, |
||
46 | SUM(tg.chartRank3) as chartRank3, |
||
47 | SUM(tg.pointChart) as pointChart, |
||
48 | SUM(tg.pointGame) as pointGame, |
||
49 | COUNT(DISTINCT tg.game) as nbGame |
||
50 | FROM VideoGamesRecords\CoreBundle\Entity\TeamGame tg |
||
51 | JOIN tg.team t |
||
52 | WHERE tg.team = :team |
||
53 | GROUP BY t.id"); |
||
54 | |||
55 | $query->setParameter('team', $team); |
||
56 | $result = $query->getResult(); |
||
57 | if ($result) { |
||
58 | $row = $result[0]; |
||
59 | |||
60 | $team->setAverageGameRank($row['averageGameRank']); |
||
61 | $team->setChartRank0($row['chartRank0']); |
||
62 | $team->setChartRank1($row['chartRank1']); |
||
63 | $team->setChartRank2($row['chartRank2']); |
||
64 | $team->setChartRank3($row['chartRank3']); |
||
65 | $team->setPointChart($row['pointChart']); |
||
66 | $team->setPointGame($row['pointGame']); |
||
67 | $team->setNbGame($row['nbGame']); |
||
68 | } |
||
69 | |||
70 | // 2 game Ranking |
||
71 | $data = [ |
||
72 | 'gameRank0' => 0, |
||
73 | 'gameRank1' => 0, |
||
74 | 'gameRank2' => 0, |
||
75 | 'gameRank3' => 0, |
||
76 | ]; |
||
77 | |||
78 | //----- data rank0 |
||
79 | $query = $this->em->createQuery(" |
||
80 | SELECT |
||
81 | t.id, |
||
82 | COUNT(tg.game) as nb |
||
83 | FROM VideoGamesRecords\CoreBundle\Entity\TeamGame tg |
||
84 | JOIN tg.game g |
||
85 | JOIN tg.team t |
||
86 | WHERE g.nbTeam > 1 |
||
87 | AND tg.rankPointChart = 1 |
||
88 | AND tg.nbEqual = 1 |
||
89 | AND tg.team = :team |
||
90 | GROUP BY t.id"); |
||
91 | |||
92 | $query->setParameter('team', $team); |
||
93 | $row = $query->getOneOrNullResult(); |
||
94 | if ($row) { |
||
95 | $data['gameRank0'] = $row['nb']; |
||
96 | } |
||
97 | |||
98 | //----- data rank1 to rank3 |
||
99 | $query = $this->em->createQuery(" |
||
100 | SELECT |
||
101 | t.id, |
||
102 | COUNT(tg.game) as nb |
||
103 | FROM VideoGamesRecords\CoreBundle\Entity\TeamGame tg |
||
104 | JOIN tg.team t |
||
105 | WHERE tg.rankPointChart = :rank |
||
106 | AND tg.team = :team |
||
107 | GROUP BY t.id"); |
||
108 | |||
109 | $query->setParameter('team', $team); |
||
110 | |||
111 | for ($i = 1; $i <= 3; $i++) { |
||
112 | $query->setParameter('rank', $i); |
||
113 | $row = $query->getOneOrNullResult(); |
||
114 | if ($row) { |
||
115 | $data['gameRank' . $i] = $row['nb']; |
||
116 | } |
||
117 | } |
||
118 | |||
119 | $team->setGameRank0($data['gameRank0']); |
||
120 | $team->setGameRank1($data['gameRank1']); |
||
121 | $team->setGameRank2($data['gameRank2']); |
||
122 | $team->setGameRank3($data['gameRank3']); |
||
123 | |||
124 | // 3 Badge Ranking |
||
125 | $query = $this->em->createQuery(" |
||
126 | SELECT |
||
127 | t.id, |
||
128 | COUNT(tb.badge) as nbMasterBadge, |
||
129 | SUM(b.value) as pointBadge |
||
130 | FROM VideoGamesRecords\CoreBundle\Entity\TeamBadge tb |
||
131 | JOIN tb.badge b |
||
132 | JOIN tb.team t |
||
133 | WHERE b.type = :type |
||
134 | AND tb.team = :team |
||
135 | AND tb.ended_at IS NULL |
||
136 | GROUP BY t.id"); |
||
137 | $query->setParameter('type', 'Master'); |
||
138 | $query->setParameter('team', $team); |
||
139 | |||
140 | $row = $query->getOneOrNullResult(); |
||
141 | if ($row) { |
||
142 | $team->setNbMasterBadge($row['nbMasterBadge']); |
||
143 | $team->setPointBadge($row['pointBadge']); |
||
144 | } |
||
145 | |||
146 | $this->em->persist($team); |
||
147 | $this->em->flush(); |
||
148 | |||
149 | $event = new TeamEvent($team); |
||
150 | $this->eventDispatcher->dispatch($event, VideoGamesRecordsCoreEvents::TEAM_MAJ_COMPLETED); |
||
151 | } |
||
220 |