| Conditions | 6 |
| Paths | 24 |
| Total Lines | 63 |
| Code Lines | 39 |
| 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 |
||
| 28 | public function getTop(DateTime $date1Begin, DateTime $date1End, DateTime $date2Begin, DateTime $date2End, int $limit = 20): array |
||
| 29 | { |
||
| 30 | /** @var DwhGameRepository $dwhGameRepository */ |
||
| 31 | $dwhGameRepository = $this->dwhEntityManager->getRepository('VideoGamesRecords\DwhBundle\Entity\Game'); |
||
| 32 | |||
| 33 | /** @var CoreGameRepository $coreGameRepository */ |
||
| 34 | $coreGameRepository = $this->defaultEntityManager->getRepository('VideoGamesRecords\CoreBundle\Entity\Game'); |
||
| 35 | |||
| 36 | $gameList1 = $dwhGameRepository->getTop( |
||
| 37 | $date1Begin, |
||
| 38 | $date1End, |
||
| 39 | $limit |
||
| 40 | ); |
||
| 41 | $gameList2 = $dwhGameRepository->getTop( |
||
| 42 | $date2Begin, |
||
| 43 | $date2End, |
||
| 44 | $limit |
||
| 45 | ); |
||
| 46 | |||
| 47 | // Get old rank |
||
| 48 | $oldRank = array(); |
||
| 49 | foreach ($gameList2 as $key => $row) { |
||
| 50 | $oldRank[$row['id']] = $key + 1; |
||
| 51 | } |
||
| 52 | |||
| 53 | $nbPostFromList = 0; |
||
| 54 | for ($i = 0, $nb = count($gameList1) - 1; $i <= $nb; ++$i) { |
||
| 55 | $idGame = $gameList1[$i]['id']; |
||
| 56 | if (isset($oldRank[$idGame])) { |
||
| 57 | $gameList1[$i]['oldRank'] = $oldRank[$idGame]; |
||
| 58 | } else { |
||
| 59 | $gameList1[$i]['oldRank'] = null; |
||
| 60 | } |
||
| 61 | |||
| 62 | $game = $coreGameRepository->find($idGame); |
||
| 63 | $gameList1[$i]['game'] = $game; |
||
| 64 | $nbPostFromList += $gameList1[$i]['nb']; |
||
| 65 | } |
||
| 66 | |||
| 67 | try { |
||
| 68 | $nbGame = $dwhGameRepository->getTotalNbGame($date1Begin, $date1End); |
||
| 69 | } catch (NoResultException | NonUniqueResultException $e) { |
||
| 70 | // OK |
||
| 71 | } |
||
| 72 | |||
| 73 | try { |
||
| 74 | $nbTotalPost = $dwhGameRepository->getTotalNbPostDay($date1Begin, $date1End); |
||
| 75 | } catch (NoResultException | NonUniqueResultException $e) { |
||
| 76 | // OK |
||
| 77 | } |
||
| 78 | |||
| 79 | $gameList = ToolsRanking::addRank( |
||
| 80 | $gameList1, |
||
| 81 | 'rank', |
||
| 82 | ['nb'], |
||
| 83 | true |
||
| 84 | ); |
||
| 85 | |||
| 86 | return array( |
||
| 87 | 'list' => $gameList, |
||
| 88 | 'nbPostFromList' => $nbPostFromList, |
||
| 89 | 'nbItem' => $nbGame, |
||
| 90 | 'nbTotalPost' => $nbTotalPost, |
||
| 91 | ); |
||
| 94 |