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