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