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