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